Description
HTML element <a>
(also known as anchor tag) defines a hyperlink, which can be used in many ways.
- Link to another HTML document using the
href
attribute - Bookmark a specific section inside an HTML document using the
id
attribute. - Link to an email address
- Links to file downloads
By default, links will appear as below in all browsers. However, the default appearance of links can be changed using CSS.
- An unvisited link is underlined and blue
- A visited link is underlined and purple
- An active link is underlined and red
Syntax
Here is the basic syntax of this tag.
<a href="url">Link display content</a>
Examples
Basic Usage
<a href="https://randomcodez.com">Random Codez Website</a>
Using title attribute
<a href="https://randomcodez.com" title="Random Codez Official Website">Visit Our Website</a>
Using target attribute
<a href="https://randomcodez.com" target="_blank">Random Codez Website</a>
Link over an image
<a href="https://randomcodez.com" target="_blank">
<img src="logo.png" alt="Random Codez logo" style="width:50px; height:50px;">
</a>
Link for a container
<a href="https://randomcodez.com">
<div style="border: 2px solid orange; padding: 20px;">
<h2>Random Codez</h2>
<p>For Online Tutorials, Articles, Videos and many more..</p>
<p>For Online Tools</p>
</div>
</a>
Link for an email address
<a href="mailto:feedback@randomcodez.com">Send us an email</a>
Link for file downloads
<a href="files/sample.txt">File Download Link</a>
Link for webpage bookmarks
<a href="#sectionA">Section A on same web page</a>
<a href="other.html#sectionA">Section A on other web page</a>
Attributes
The following table shows the list of supported and unsupported attributes for the <a>
tag.
Attribute Type | Details |
Tag-Specific Attributes | The tag <a> has some tag-specific attributes listed in the below table. |
Global Attributes | Like all other HTML tags, the tag <a> also supports HTML Global Attributes. |
Event Attributes | The tag <a> also supports the HTML Event Attributes. |
Here is a list of attributes that are specific to the <a>
tag.
Attribute | Value | Description | HTML5 Support |
download | filename | Specifies that the target will be downloaded when a user clicks on the hyperlink | Yes - New in HTML5 |
href | URL | Specifies the URL of the page the link goes to | Yes |
hreflang | language_code | Specifies the language of the linked document | Yes |
media | media_query | Specifies what media/device the linked document is optimized for | Yes - New in HTML5 |
ping | list_of_URLs | Specifies a space-separated list of URLs to which, when the link is followed, post requests with the body ping will be sent by the browser (in the background). Typically used for tracking. | Yes |
referrerpolicy | no-referrer no-referrer-when-downgrade origin origin-when-cross-origin same-origin strict-origin-when-cross-origin unsafe-url |
Specifies which referrer information to send with the link | Yes |
rel | alternate author bookmark external help license next nofollow noreferrer noopener prev search tag |
Specifies the relationship between the current document and the linked document | Yes |
target | _blank _parent _self _top |
Specifies where to open the linked document | Yes |
type | media_type | Specifies the media type of the linked document | Yes |
Browser Compatibility
The tag <a>
is supported in most modern browsers.
- Google Chrome 1+
- Internet Explorer or Edge 2+
- Firefox 1+
- Apple Safari 1+
- Opera 4+