In HTML, the anchor tag <a> is used to create hyperlinks. Hyperlinks are references to other web pages, resources, or locations, allowing users to navigate from one page to another or within the same page.
Here's the basic syntax of the anchor tag:
<a href="URL">Link Text</a>
Output:
- href: The href attribute specifies the destination URL (Uniform Resource Locator) to which the link points. It can be an absolute or relative URL.
- Link Text: The text between the opening <a> and closing </a> tags is the visible link text.
Here are some examples:
1.External Link:
<a href="https://www.example.com">Visit Example.com</a>
2.Internal Link (Relative URL):
<a href="/about">About Us</a>
In this case, the link points to a page named "about" in the same website.
3. Link to an Email Address:
<a href="mailto:info@example.com">Email Us</a>
Clicking this link will open the user's default email client to send an email to "info@example.com."
4. Link to a Specific Section on the Same Page (Anchor Link):
<a href="#section1">Go to Section 1</a>
In this example, you would need an element on the page with the id attribute set to "section1" for the link to jump to that specific section.
5. Link with Target Attribute (Open in New Tab):
<a href="https://www.example.com" target="_blank">Open in New Tab</a>
The target="_blank" attribute opens the link in a new browser tab or window.
These are just a few examples of how the anchor tag can be used. The anchor tag is a fundamental element for creating navigation and connecting various parts of a website.