HTML Links

Links are nothing but which is used to refer another document or web page.

HTML uses the <a>anchor tag to create a link.

In all browsers by default, links will appear as follows:

  1. An unvisited linkwhich is underlined and colored blue
  2. An active linkwhich is underlined and colored red
  3. A visited linkwhich is underlined and colored purple

 

The Anchor Tag:

An anchor tag is used to point any concerned resource on the Web page such as HTML page, an image, a sound file, video clip etc.

 

The syntax of creating an anchor:

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

 

The href attribute is used to locate the address of the document or page which is linked with it.

Text present in between the anchor tag will be considered as hyperlink.

 

For example,

<a href="http://www.programmingtute.com/"> Visit Pt</a>

 

Output: Visit Pt

 

The Target Attribute:

 

This attribute is used to specify where the linked document has to be opened.

By default, the link will open in the current window.

If you want that link to be opened in some other or new window then you have to use this attribute.

We have to set the target attribute to “_blank“, and then only the link will open in a new browser window.

 

For example:

 

<a href="http://www.programmingtute.com/target="_blank"> Visit Pt</a>

 

Email Links:

 

This attribute is used to link to a mail message.

In order to create an email link, we have to use mailto: email address.

 

For example:

<a href="mailto:admin@programmingtute.com">Contact Admin</a>

 

Output: Contact Admin

 

If you want to add subject for the email message, then you have to add ?Subject=’subjectafter the email address.

 

For example:

<a href="mailto:admin@programmingtute.com?subject=Queries">Contact Admin</a>

If you want to add some email id in CC and in BCC then find the below example.

 

<a href=" mailto:admin@programmingtute.com?cc=adminl@programmingtute.com&bcc= admin2@programmingtute.com&subject= Queries&body=Please clarify my doubts!" target="_top">Send mail!</a>

The id Attribute:

The id attribute can be used to create a bookmark inside the same HTML document.

 

Example:

An id attribute is defined inside anchor in an HTML document:

<a id="top">Display Text</a>

 

Now set a link to the “Back to top” inside the same document.To link directly to the top section then we have to add a # sign.

<a href="#top">See Again</a>

 

Output :Display Text See Again

Posted on July 12, 2014 in HTML

Share the Story

Leave a reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Back to Top