The anchor tag or a Tag is an HTML tag which is used to create links on web page. It is also known as hyperlink. Anchor tag is used to link one page to another page. It is used to create hyperlinks to other web pages or websites or files. href attribute is used in anchor tag to define the links destination.
Table of Contents
How to use Anchor Tag
To create a hyperlink the text is written between the starting anchor tag and ending anchor tag. The href attribute is used to define the destination of the link, the value of this href attribute is url address of the website, web page or a file. The syntax is shown below.
<!DOCTYPE html>
<html>
<body>
<a href="https://www.howtocodeschool.com/">HOW TO CODE SCHOOL</a>
</body>
</html>
The output of this html code would be like this.
HOW TO CODE SCHOOLBrowser support for Anchor Tag
Anchor tag is one of the primary html tags, it is also one of the most common and widely used tags. All present browsers like chrome, opera, firefox and internet explorer support this tag.
Default styling of Anchor Tag
The anchor tag is inline level element.
By default anchor tag would have three types of styling.
-
The unvisited link is blue in color and underlined.
-
The active link is red in color and underlined.
-
The visited link is purple in color and also underlined.
Note: You can change these styles on anchor tag using simple css.
Attributes used in Anchor Tag
Following attributes are used in anchor tag. href is the most important attribute of anchor tag.
href attribute
href attribute is used in anchor tag. It defines the url of the link destination, it could be any page, website or file.
charset attribute
It is used for anchor tag. It defines the character encoding. It is not supported in HTML5.
coords attribute
It defines the coordinates of the link element or anchor tag. It is also not supported in HTML5.
download attribute
It is also used in anchor tag and it specifies that the file should be downloaded when the link is clicked.
hreflang attribute
It is used in anchor tag to define the language of the linked document.
media attribute
It is used for anchor tag to explain that which device is optimal for the linked web page or document.
name attribute
It defines the name of the anchor element. It is not supported in HTML5.
ping attribute
It specifies the list of urls. When the link is clicked the ping will be sent by the browser to these urls, it is used for tracking purposes.
referrerpolicy attribute
It is used in anchor tag to specify which referrer to send.
rel attribute
It is used for anchor tag. It defines the relationship of linked document or file with the current file or page.
rev attribute
It does the same thing what rel attribute does but it is not supported in HTML5.
shape attribute
It specifies the shape of link element or anchor tag, It is also not supported in HTML5.
target attribute
It is used in anchor tag to specify where to open the linked page or document. For example if it's value is set to "_blank" the page will always open in new tab whenever the link is clicked.
type attribute
It defines the media type of the linked document.
Global Attributes support in Anchor Tag
Anchor tag or a tag does support the Global Html attributes.
Event Attributes support in Anchor Tag
Anchor tag or a tag also supports the Event Html attributes.
HTML Anchor Tag Video
Watch our video on anchor tag and subscribe our Youtube Channel.