HTML Links

Mohammed Imtiyaz Nov 29, 2014

A hyperlink is a group of words that can be clicked to navigate to another page.

When you place the cursor over the link in the webpage, the arrow will turn into litle hand.

The most important attribute of hyperlink is href attribute, which indicates the link's destination.

Syntax

<a href="URL">Your Text</a>

URL: Uniform Resource Locator
a: Anchor
href: Hypertext Reference

Example

<a href="www.ittutorials.in">Visit ittutorials.in</a>
Tip: By default, links will appear as follows in all browsers.
  • An unvisited link is underlined and is blue in color.
  • A visited link is underlined and is purple in color.
  • An active link is underlined and is red in color.

Html Target Attribute

The target attribute specifies where to open the linked document.

Syntax

<a href="url" target="_blank">Text</a>

Example

<a href="www.ittutorials.in" target="_blank">Visit ittutorials.in</a>

Target attributes and their descriptions

Attributes Description
_blank Opens the linked document in a new window or tab
_self Opens the linked document in the same window as it was clicked
_parent Opens the linked document in the parent window
_top Opens the linked document in the full body of the window

Example

Link to an element with a specified id within a page:

<a href="#top">Go to top</a>
Note: The name attribute is not supported in HTML5

Example

Link to an email address with a specified subject

<a href="mailto:someone@example.com?Subject=Hi%20again">Send email mail!</a>
Note: will only work if you have mail installed

Example

Link to a JavaScript

<a href="javascript:alert('Hello World!');">Execute JavaScript</a>