How to use <a> Tag HTML and Attributes used in Anchor Tag
Today we’ll be taking a look at the anchor tag which is one of the most used tags in web development.
It is crucial to understand the anchor tag completely before getting into the actual coding part. The Anchor tag <a> along with its ‘href’ i.e. “Hyper REFerence” attribute is used to link webpages, locations, emails, etc.
Given below is an example of an anchor tag :
While using anchor tag attributes plays an important role, let us take a closer look at the attributes which are used in anchor tags.
Attributes used in Anchor Tag
1. a Href Attributes used in Anchor Tag
The href attribute is like the default attribute to redirect to another webpage when the word between the anchor tag is clicked.
Href attribute can be used to
- the point at different sections on the same webpage.
- link different web pages.
- create a call link with “tel”
- create a mail link with “mailto”
2. Download Attributes used in Anchor Tag
The download attribute is used to download the specified file linked in the href Attribute.
<a href="URL" download="filename">download</a>
The value passed in the download attribute i.e “filename” will be used as the name of the file which will be downloaded.
3.Hreflang Attributes used in Anchor Tag
Hreflang attribute is used to specify the language of the linked page in the href attribute.
<a href="URL" hreflang="lang_code"></a>
NOTE: The language code is a two-letter code used to identify the languages.
The Hreflang can only be used when the Href attribute is defined.
4. Target Attributes used in Anchor Tag
The Target attribute specifies how to open the linked webpage.
<a href=”URL” target=”_blank”></a>
By default, the value of the target attribute is set to “_self”.
Following are the values used in the target attribute and what are they used for:
- _self – opens the webpage in the same tab.
- _blank – opens the webpage on a new tab.
- _parent – opens the web page in the parent frame.
4.Rel Attributes used in Anchor Tag
Relation attribute specifies the relation between the linked webpage and the current webpage.
<a href="URL" rel="value"></a>
The value is accepted in the rel attribute.
Leave a comment below and let us know if you have any queries.
Restaurant Website Using HTML And CSS With Source Code
You can visit our other useful blog for collecting fronted development knowledge. thank you for visiting our website!
Written by: @OmBandiwan