HTML anchor tag
HTML

HTML anchor tag

Mishel Shaji
Mishel Shaji

What is an anchor tag?

The anchor tag defines a hyperlink. By clicking on an anchor tag, you can navigate from one page to another. By default, all links will be blue and underlined. When you visit a link, it’s color will change from Blue to Purple.

Example:

<a href="https://www.geekinsta.com">Click here to visit this site</a>

Output

Click here to visit this site

Attributes

ATTRIBUTEDEFINITION
hrefSpecifies the target URL.
targetSpecifies where the link should be opened.
idSpecifies the id of the element.

The target attribute

This attribute specifies where the link should be opened. Its values can be _blank, _self, _parent and _top. If you do not specify the target attribute, _self will work.

  • _self – This is the default value. If the target is set to _self, the link will be opened in a separate window.
  • _blank – If the target is set to _blank, the link will be opened in a new window.
  • _top – This will open the link as the top document.
  • _parent – This opens the link in the parent window.

<a href="https://www.geekinsta.com" target="_blank">Open me in another window</a>

Anchor tag – Advanced

Using anchor tag, you can create an email link.

<a href="mailto:someone@somewhere.com">Email someone</a>

Output

Email someone

You can add an option to dial a number using <a> tag.

<a href="tel:00112233">Call</a>

Output

Call