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:
- An unvisited linkwhich is underlined and colored blue
- An active linkwhich is underlined and colored red
- 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.
<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.
<a href="http://www.programmingtute.com/target="_blank"> Visit Pt</a>
This attribute is used to link to a mail message.
In order to create an email link, we have to use mailto: email address.
<a href="mailto:firstname.lastname@example.org">Contact Admin</a>
Output: Contact Admin
If you want to add subject for the email message, then you have to add ?Subject=’subject’after the email address.
<a href="mailto:email@example.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:firstname.lastname@example.orgemail@example.com&bcc= firstname.lastname@example.org&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.
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