What Are Anchor Tags in HTML?
Anchor tags in HTML code are HTML elements used to create hyperlinks in webpages. They allow you to link to another webpage, a specific section of a page, an email address, a file, or any other URL. They are also known as anchor elements or <a> tags.
A complete anchor element or <a> tag looks like this:

The element starts with â<a,â ends with â</a>.â And contains various attributes that make up the full tag.Â
Weâll get into the attributes below.Â
You can also use the anchor tag to create anchor links. Anchor links (or âjumpâ links) link to different sections of the same webpage.
When you create text links with the âaâ tag, youâll need to use some kind of anchor text. Anchor text is the part of the link thatâs clickable. Google uses this text to learn more about the link and the content it points to.
Your site probably has a lot of anchor tag links already. Use a tool like Site Audit to identify them and fix any issues that they might have.
Configure the tool and run your first crawl.
After that, go to the âIssuesâ tab and select âLinksâ from the âCategoryâ drop-down.

Youâll see if there are any issues detected.

The tool also offers advice on how to fix each issue. Just click on the âWhy and how to fix itâ link.

HTML Anchor Element Attributes
You can add different attributes to your anchor tags to specify what you want to happen when a user clicks.
And to add semantic meaning for browsers and web crawlers.Â
Here are the most important attributes:
Href
The âhref,â short for hypertext reference, attribute specifies the target for the anchor element.Â
Like this:Â
<a href="URL">Itâs commonly used to define the URL of the page the tag links to. But you can also use it to link to files, email addresses, phone numbers, and more.
For example, a link to a webpage would use the following snippet of code:
<a href="https://example.com">Website</a>The href anchor tag is the URL between quotation marks. And the word âWebsiteâ is the anchor text: the visible and clickable text of the link.
Hreflang
The âhreflangâ attribute indicates the language of the linked resource using the ISO 639-1 two-letter language code.
It looks like this:Â
<a hreflang="language_code">If you want to specify English as the pageâs language, use the following snippet of code:
<a href="https://example.com" hreflang="en">Website</a>The hreflang attribute is the two-letter country code: âenâ wrapped in quotation marks.Â
Note: You can only use the hreflang attribute if youâve also used the href attribute.Â
Download
The âdownloadâ attribute tells the browser to download the linked resource instead of opening it.Â
Like this:
<a download="filename">For example, if the resource is a PDF, use the following code:
<a href="example.pdf" download="Example">The attribute is the name of the file. In this case, âExample.âÂ
If you donât specify a filename, it will pull the documentâs original filename.
Rel
The ârelâ attribute specifies the relationship between the current and linked resource.Â
Like this:
<a rel="value">The most common ârelâ attribute values include the following:
- rel=âalternateâ: To identify the linked resource as an alternate version of the current resourceÂ
- rel=âauthorâ: To provide a link to the author of the resource
- rel=âbookmarkâ: To indicate the URL is permanent and can be used for bookmarking. Often used to quickly navigate to a specific section of a long article, for example.Â
- rel=âhelpâ: To state the link contains a help document for the current pageÂ
- rel=ânextâ: To specify the link is the next page in the series. For articles, news, or photo galleries, for example.Â
- rel=âprevâ: To specify the link is the previous page in the series
- rel=ânofollowâ: To indicate to search engines not to follow the link. In other words, you donât wish to endorse the link
- rel=âsearchâ: To specify the linked page can be used to search for content on the page or site
And others.Â
For example, you can use the following code to indicate the link is a page about the author of the article:
Article written by <a href="https://example.com/+AuthorName"Â
rel="author">Author Name</a>.Note: Search engines like Google use the ârelâ attribute to get more information about a link.Â
Target
The âtargetâ attribute tells the browser where to open the link, such as in the same tab, a new tab, a new window, or an iframe.
It looks like this:
<a target="value">The different values include:
- â_selfâ: To open the link in the same frame (often the same tab or window)
- â_blankâ: To open the link in a new tab or window. This is the most common approach
- â_parentâ: To open the link within the next-level-up frame, known as a parent frame
- â_ topâ: Ignores all frames and opens the link as the top document in the same browser window
- âframenameâ: To open the link in the named frame, such as a video playing within an iframe.Â

For example, if we want the link to open in a new tab, we can write:
<a href="https://example.com" target="_blank">Website</a>Anchor Tag Examples
Letâs consider a few examples of where and how to use anchor tags.
Link to an Element on the Same Page
You can use anchor tags to link to elements on the same page. And help users better navigate and consume your content.Â
Start with the following:
- Attach an âidâattribute to the section you want to link to
- Add the âidâ attribute to the anchor tag youâre linking from
For example, say weâre writing an article about SEO and want to link to the heading âLocal SEO.â
Go to the heading and attach an âidâattribute to it.
Like this:
<a id="LocalSEO"><h2>Local SEO</h2></a>Go to the text you want to add a link from and add an âhrefâattribute to create the anchor link.Â
However, instead of adding a link to a webpage, add the anchor ID with a pound sign (#).Â
Like this:
<a href="#LocalSEO">local SEO</a>When the reader clicks on the link, theyâll âjumpâ to the H2 header with the "LocalSEO" id.
Link to an Email Address
You can also have a link that directs users to send an email to a specific address.Â
When a user clicks a link, the browser will open the computerâs default email client, such as the Apple Mail app on a Macbook laptop. And auto-populate the recipient address with the one specified in the attribute.Â
This is called the âmailtoâprotocol. Itâs added to the âhrefâ attributeâs value.Â
Like so:
<a href="mailto:person@example.com">Send email to person</a>If someone clicks the link above, the default email client will open with the email address indicated in the âToâ field.Â

Link to a Phone Number
Just as you can link to an email address, you can also link to a phone number.Â
Add the âtelâ protocol followed by the phone number.Â
Like this:
<a href="tel:+34673245198">+34673245198</a>Clicking the link will call the number on capable devices (such as phones or on computers with Skype or FaceTime).
Link to a File Download
Use the âdownloadâ attribute to make the link download a file directly.Â
For example, you might use it to help readers download an infographic or PDF.
To implement it, set the âhrefâ attribute. Its value is the actual file.Â
Like this:
<a href="/images/infographic.jpg" download="infographic">Clicking the link will download the infographic.Â
Note: You can add the name of the file as the value of the âdownloadâ attribute. But itâs optional. If you donât, the browser will use the original filename.Â
Are Anchor Links Good for User Experience?Â
Anchor links can help improve user experience (UX). Readers use them to navigate, and they can provide a better browsing experience.
Anchor links are commonly used in a table of contents, for example, to help navigate long or visually dense pages.Â
When readers land on a page, they want to know whether the information is useful or relevant to their search query.Â
A table of contents that includes clear, clickable anchor links summarizes your page and helps readers âjumpâ to the section theyâre most interested in.
Are Anchor Links Good for SEO?
Anchor links help improve page experience. And can earn featured snippets. Both of which can help improve your rankings over time.
Google can also include anchor links in your pageâs search snippet.Â
Like this:

Google includes an anchor link to âPlotâ and âCastâ on a page about John Wick, the movie. Which helps searchers âjumpâ directly to that section from the search engine results page (SERP).Â
Which means:
It can be worth including anchor links on your page.Â
Use them to tell Google more about your content. And help readers find and jump to the sections they want to read.Â
Audit Your Siteâs Links to Improve Your SEO RankingÂ
One of the most important SEO best practices is regularly auditing your site. Audits can help you find and fix issues holding your site back from ranking.Â
You can also audit to find specific issues. Like issues with links, in this case.Â
Semrush Site Audit crawls your entire website and helps you resolve these issues.
Open the tool, enter your domain name, and click âStart Audit."

The âSite Audit Settingsâ pop-up will appear.

Configure the basic settings and click âStart Site Audit."
After the audit is complete, navigate to the âIssuesâ tab.

To see link-specific issues, click the âCategoryâ drop-down, and select âLinks.âÂ

These are all the errors, warnings, and notices pertaining to your siteâs links.Â

Click on the âWhy and how to fix itâ link to learn more about each issue and how to address it.

Plus, you can schedule audits to run automatically.
To do so, click the gear icon on the top-right corner. Scroll down to the audit settings, and click on âSchedule.â

Then, click the drop-down to schedule the audit to run on your preferred day of the week.Â
Click âSave.â

Pay close attention to your link issues. And fix them as soon as possible.
