HTML <a> tag
Using the <a> tag, you can link one document to other documents.
This is also called as anchor tag.
In short, it defines an hyperlink using the href attribute to link from one page to other pages.
You can also use this tag to create bookmark inside the HTML document using the id attribute.
Syntax:
<a href=”url”>Link name</a>
How Browser will display
Inline
Difference between HTML4.01, XHTML and HTML5
HTML4 | XHTML | HTML5 |
---|---|---|
It can be hyperlink or anchor | No difference compared to HTML4 | It can only be hyperlink and bookmark |
Attributes used with <a> tag
Attribute | Description |
---|---|
download | It downloads the target when user clicks on the hyperlink with a file-name. It is used only with the href attribute. |
href | It describes the URL of the target page link. |
hreflang | sets the language of the target URL link using a language-code. You must code the href attribute when you wish to use the hreflang attribute. |
media | This informs the purpose of the target URL and what type of task of the media/device is optimized for this URL. This uses media query for this purpose.Always use the href attribute when you wish to use this attribute. |
type | Describes type of media type for the target link URL. You must use the href attribute when you code this attribute. |
ping | To track list of URLS to post request with the ping. |
referrerpolicy | To set the kind of referrer. It can take values like - |
rel | This sets the relation between the current document and the linked URL.It can take values like - Out of these, nofollow, noreferrer, noopener are important. To use this attribute, you must also use the href attribute. |
target | Sets the destination tab or window where the target link will be opened.It can take the followging values - Apart from the above values, you can also mention a name of the frame if you want the target URL to open in a frame. You must code the target attribute only when you use the href attribute. |
charset | Defines a character-set for the target link using a character encoding. (HTML5 does not support this <a> charset attribute). |
coords | Sets the coordinates of the target link using a coordinates. (HTML5 does not support this <a> coords attribute). |
name | sets a name for the anchor using a section name. (HTML5 does not support this attribute). It is better to use id attribute. |
rev | Uses a text to create a relationship between the current document and the target linked document. (HTML5 does not support this attribute). |
shape | To define the shape of the link. It can take the followging values - (HTML5 does not support this attribute). |
When the user does not visit a link, it is called as Unvisited Link. If the user visits the link, it is called as Visited Links. Similarly, the duration when the user clicks the link for some milli-seconds or micro-seconds, the exact time duration is the active link.
Note/Info:
By default,
- An Unvisited Link is underlined and in blue color. The color also depends on the internal value of the color which is set for the document.
- A Visited Link is underlined and in purple color. The color also depends on the internal value of the color which is set for the document.
- An Active Link is underlined and in red color. The color also depends on the internal value of the color which is set for the document.
The color of the Unvisited Link, Visited Link, or Active Link also depends on the internal value of the color which is set for the document.
If you want to change the default behavior of the links, or set the color of the link on mouse-over, you should use CSS.
Default CSS Value
For unvisited link:
color: blue;
text-decoration: underline;
cursor:auto;
For visited link:
color: purple;
text-decoration: underline;
cursor:auto;
For active link:
color: red;
If you have set an internal Text color or text decoration for the entire HTML document, then it will take that internal value NOT the above shown values.
Global Attributes
The <a> tag supports Global attributes.
Event Attributes
The <a> tag supports Event attributes.
Supporting Browsers
Related Tags
<base>.