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:
- Link to another webpage:
<a href="https://fullstackadda.com">Visit fullstackadda.com</a>
- Link to a specific section on the same page:
<a href="#section1">Go to section 1</a>
...
<h2 id="section1">Section 1</h2>
- Link to a specific email address:
<a href="mailto:example@example.com">Send an email</a>
- Link to open a pdf file
<a href="example.pdf">Download PDF</a>
- 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.
EXAMPLE:
<!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:
- 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.
- 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. - 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.
- 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.
- Download anchors: These are used to create a link that, when clicked, prompts the user to download the file specified in the “href” attribute.
- Bookmark anchors: These are used to create a link that, when clicked, takes the user to a specific location on the same webpage.
- 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 name | Values | Notes |
---|---|---|
hreflang | Specifies the language of the linked resource. | |
download | Directs 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. |
title | text | Defines the title of a link, which appears to the user as a tooltip. |
href | url | Specifies the linked document, resource, or location. |
- The
<a>
(anchor) tag in HTML is used to create hyperlinks. - 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