HTML Anchor Tag

HTML Anchor TagHTML Anchor Tag (<a>) is used to create or provide a link to a resource or to another web page or to a different location on the same web page.

The HTML Anchor Tag is written as <a>.

The most common use of the HTML Anchor Tag is to provide a Hyperlink to another webpage and in order to do so we need to use the href attribute of the HTML Anchor Tag.

By default the hyperlinks will appear as follows in all the browsers.

  • Unvisited Link: Underlined and blue in color
  • Visited Link: Underlined and purple in color
  • Active Link: Underlined and red in color

The HTML Anchor Tag won’t be able to do anything on its own; it needs attributes and value to function properly.


Attributes available for the HTML Anchor Tag are:

Attribute Name

Value of Attribute

Description of Attribute

charset char_encoding Defines the character set of the linked document (Not supported in HTML 5)
cords coordinates Defines the co-ordinates of the link (Not supported in HTML 5)
href URL Specifies the URL of the resource or webpage the links points to.
hreflang language_code Defines the language of the linked document.
media media_query Specifies for what media/device the link is optimized.
name section_name Defines the name of the anchor (Not supported in HTML 5)
rel alternate
author
bookmark
help
license
next
nofollow
noreferrer
prefetch
prev
search
tag
Defines the relationship between the current resource/ webpage and the linked resource/webpage.
rev text Defines the relationship between the linked resource/ webpage and the current resource/webpage. (Not supported in HTML 5)
shape default
rect
circle
poly
Defines the shape of the link (Not supported in HTML 5)
target _blank
_parent
_self
_top
framename
Defines where to open the linked resource/webpage
type MIME_type Defines the MIME type of the linked resource/webpage

Apart from the above mentioned attributes the HTML Anchor Tag also supports the HTML Global Attributes and HTML Event Attributes.


Example of HTML Anchor Tag

HTML anchor tag Code

Output

<a href="http://www.techhoney.com/"
target="_blank">Link for Techhoney </a>
Link for Techhoney

Here in the above HTML Anchor Tag example we can see that the href attribute has value of “http:/www.techhoney.com” and the target attribute has value of “_blank” which means that once we click on the above hyperlink we will open the home page of www.techhoney.com in a new browser window/tab.

Here the target attribute’s value allows us to open the linked resource/webpage in new browser window/tab.


HTML Anchor Tag Supporting Browsers

S. No. Browser Supported(Yes/No)
1 Internet Explorer Yes
2 Firefox Yes
3 Google Chrome Yes
4 Opera Yes
5 Safari Yes

Important points about HTML anchor tag:

hreflang, media, rel, target, and type attributes cannot be present in the HTML anchor tag if the href attribute is not present.
by default any hyperlink will open in the same browser window until and unless specified with the target attribute.


Tagged , , , , , , , . Bookmark the permalink.