Understanding the HTML <a>
Tag
The <a>
tag, commonly known as the anchor tag, is used to create links between different pages, within the same page, or to any location on the internet. It's one of the fundamental components of the web, facilitating navigation and connectivity between resources.
Basic Usage of the <a>
Tag
The <a>
tag uses the href
attribute to specify the URL of the page the link goes to:
<a href="https://www.example.com">Visit Example</a>
This example creates a link to the homepage of "www.example.com". When clicked, it will take the user directly to that URL.
Main Attributes of the <a>
Tag
Attribute | Description |
---|---|
href |
Specifies the URL of the page the link goes to. |
title |
Provides additional information about the link, usually shown as a tooltip when the mouse hovers over the link. |
target |
Defines where to open the linked document (in a new tab, in the same tab, etc.). |
rel |
Specifies the relationship between the current document and the linked document. |
Values for the target
Attribute
Value | Description |
---|---|
_blank |
Opens the linked document in a new window or tab. |
_self |
Opens the linked document in the same frame as it was clicked (this is default). |
_parent |
Opens the linked document in the parent frame. |
_top |
Opens the linked document in the full body of the window. |
Using the <a>
Tag for Email Links
You can also use the <a>
tag to create an email link using the mailto:
protocol:
<a href="mailto:example@example.com">Send Email</a>
This link, when clicked, will open the user's default email program with the "To" field already filled out with "example@example.com".
Conclusion
The <a>
tag is a versatile tool in HTML, essential for creating hyperlinks. Understanding its attributes and how they work can greatly enhance the usability and functionality of your web pages, providing a better user experience through effective navigation and linking strategies.