Anchor Tag and its attributes


The Anchor Tag(<a>) is used to link web pages to one another and marks the text as a hypertext link.


Linking can be done in two ways:


The <a> tag is used to:

  1. To link one section of the web page to another section on the same web page.
  2. To link the web pages within the same website.
  3. To link to a web page of another website.


For Example:
<a href ="https://www.kodeblox.com"> Home | Kode.Blox </a>

The href attribute stands for Hypertext Reference.

The value of href attribute can contain links to another web page or another section of the same web page.


Internal Linking

Internal Linking involves linking the different sections of the same web page.

Internal Linking requires two instances of <a> tag.

  1. id attribute
    You have to assign an id to refer to a section of the page, which is referred to as an internal link to the same page.
  2. href attribute
    The value of the href attribute for internal linking should be the id of the section followed by the hash sign(#).


For Example:
Introduction...
<a href ="#part1">Go to Part-1 </a>
<a href ="#part2">Go to Part-2 </a>
<a href ="#part3">Go to Part-3 </a>

<a id ="part1">Part-1 </a>
<p>Content goes here (Part-1)... </p>
<a id ="part2">Part-2 </a>
<p>Content goes here (Part-2)... </p>
<a id ="part3">Part-3 </a>
<p>Content goes here (Part-3)... </p>


External Linking

You can also inter-link the various web pages of your website or link to any other website on the Internet.

All you need to do is specify the URL of the page in the href  attribute.


For Example:
<a href ="https://www.kodeblox.com"> Home | Kode.Blox </a>


Using Images as Links

Images can also be used as a hyperlink to link documents.

For Example:
<a href ="https://www.google.com/">
<img src ="google-image.png" width= "320">
</a>
Google


E-mail Link

This lets you create a link that allows users to send an email quickly.

<a href ="mailto:contactsojith@gmail.com"> Send us an E-mail </a>

When you click on the link, the email program will open and fill the "To" field with the email id you mentioned.


You can also add the subject in the email by typing:

<a href ="mailto:contactsojith@gmail.com?subject=Feedback"> Submit your Feedback here</a>


Title Attribute (title)

The title attribute is used to specify titles to hyperlinks in text format.

This text appears when a user hovers the mouse over the link.

The tite attribute is an optional attribute.


For Example:
<a href ="https://www.kodeblox.com" title ="Home | Kode.Blox">Kode.Blox </a>


For Example:

<html>
<head>
<title>Example | Kode.Blox </title>
</head>
<body>
<center> <h2> <a href="https://www.fix.com/blog/master-proper-workout-form/" >Master Proper Exercise Form </a> | <a href="https://www.fix.com/blog/" >Fix.com </a> </h2> </center>
<hr>
<ul type="disc">
<li>Squats
<a href="https://www.fix.com/blog/master-proper-workout-form/"> <img src="proper-squat-form.png"> </a> </li>
<li>Planks
<a href="https://www.fix.com/blog/master-proper-workout-form/"> <img src="proper-plank-form.png"> </a> </li>
<li>Deadlifts
<a href="https://www.fix.com/blog/master-proper-workout-form/"> <img src="proper-deadlift-form.png"> </a> </li>
</ul>
</body>
</html>


Prev

Next