What is Anchor Tags in HTML
(HTML) Anchor Tag
When we have to give a link to a page in an HTML webpage, then we use <a> tag (Anchor tag).
With <a> tag we can make any content or text of our webpage clickable.
By using this tag, we can highlight the link (URL) of any important page or post to the user.
With any anchor tag, it definitely has an attribute href, about which we will understand further in this blog.
How to write <a> tag (Syntax):
<p>
Visit <a href=”https://www.hartronexam.com”>Hartron Exam</a>
</p>
List of attributes of anchor tag
href
target
hreflang
download
rel
referrerpolicy
ping
(1)- href
The href attribute contains the link (URL) where the user will reach after clicking, and it is very important.
(2)- target
With target attribute we can tell where to open the link.
There are total 4 types of values in the target attribute of Anchor tag,
Target Attribute Value And Description
(a)- _blank- To open the page in a new tab.
(b)- _self – To open the page in the current tab, which is the default <a> tag.
(c)- _parent- This value was used for frameset tag, which is not supported in HTML 5.
(d)- _top- This value was used for frameset tag, which is not supported in HTML 5.
(3)- hreflang
With hreflang attribute we can tell the language of the linked page, which is beneficial in SEO, the value of this tag contains the language code.
When a link is not in the language of our page then we should use this attribute.
To use this attribute, it is necessary to have the value of link (URL) in Angkar (<a>).
In this blog you will get the language codes of all the countries: hrefcodes
Example:
<a href=”link” hreflang=”hi”>Hindi</a>
<a href=”link” hreflang=”en”>English</a>
(4)- download
With download Attribute, we can download the content that can be downloaded by adding its link in href and get it downloaded on the user’s click.
Example:
<a href=”https://www.hartronexam.com/wp-content/uploads/2022/12/W3-logo.png” download=”Hartron Exam Logo”>
Click me to download
</a>
It is not necessary to give any name in download, if you just write “download” then it will also work.
(5)- rel
With this attribute, we clarify the relationship between our page and the page whose link is given in the href attribute, so that the browser knows how to control HTTP headers.
It includes values like alternate, canonical, stylesheet, icon, license.
(6)- referrerpolicy
With the help of this attribute, we can tell browsers and bots about the relationship of the link used in the href attribute used in the anchor tag, what information to send with that link and what not to send.
This attribute includes values like no-referrer, no-referrer-when-downgrade, origin, origin-when-cross-origin.
(7)- ping
This attribute is used to track user clicks. When a user clicks on a link, data is sent in a post request to the URL given in the pink attribute, such as what is the value of the href attribute, what is the meta data of the page. Etcetera.
Example:
<a href=”https://example.com” ping=”https://example-tracking.com/log-click”>
Example
</a>