HTML Anchor Tag

The <a> (anchor) tag in HTML is used to create hyperlinks. HTML Anchor Tag

Hyperlinks allow users to navigate from one web page to another, or from one section of a web page to another. The <a> tag is often used with the “href” attribute, which specifies the URL or web address that the link should point to. HTML Anchor Tag

Examples:

  1. Link to another webpage:
<a href="https://fullstackadda.com">Visit fullstackadda.com</a>
  1. Link to a specific section on the same page:
<a href="#section1">Go to section 1</a>
...
<h2 id="section1">Section 1</h2>
  1. Link to a specific email address:
<a href="mailto:example@example.com">Send an email</a>
  1. Link to open a pdf file
<a href="example.pdf">Download PDF</a>
  1. Link to open a phone number
<a href="tel:+1234567890">Call us</a>

You can also use “target” attribute to open the link in new tab or window.

<a href="https://www.example.com" target="_blank">Visit example.com</a>

It tells the browser to open the link in new tab/window.

<!DOCTYPE html>  
<html>  
<head>  
    <title></title>  
</head>  
<body>  
   <p>Click on <a href="https://fullstackadda.com/" target="_blank"> this-link </a>main page to fullstackadda </p>  
</body>  
</html>  

OUTPUT: HTML Anchor Tag

Once it you click on the this-link it will navigate the mentioned url.

There are several types of anchors in HTML, including:

  1. Hyperlink anchors: These are the most common type of anchors and are used to create a link to another webpage or a specific section within a webpage.
  2. Named anchors: These are used to create a link to a specific section within the same webpage. They are created by using the “name” attribute in the <a> tag and linking to it using the “#” symbol followed by the name value.
  3. Email anchors: These are used to create a link that, when clicked, opens the default email client on the user’s device and pre-populates the “To” field with the email address specified in the “href” attribute.
  4. Phone anchors: These are used to create a link that, when clicked, initiates a phone call to the phone number specified in the “href” attribute.
  5. Download anchors: These are used to create a link that, when clicked, prompts the user to download the file specified in the “href” attribute.
  6. Bookmark anchors: These are used to create a link that, when clicked, takes the user to a specific location on the same webpage.
  7. JavaScript anchors: These are used to create a link that, when clicked, triggers a JavaScript function, rather than navigating to another webpage or location on the same webpage.

HTML Anchor Tag HTML Anchor Tag

Attributes of the anchor Element

Attribute nameValuesNotes
hreflangSpecifies the language of the linked resource.
downloadDirects the browser to download the linked resource rather than opening it.
target_blank
_parent
_self
_top
frame name
Specifies the context in which the linked resource will open.
titletextDefines the title of a link, which appears to the user as a tooltip.
hrefurlSpecifies the linked document, resource, or location.
HTML Anchor Tag
  1. The <a> (anchor) tag in HTML is used to create hyperlinks.
  2. Hyperlinks allow users to navigate from one web page to another, or from one section of a web page to another.

HTML Anchor Tag HTML Anchor Tag