Master Code
On The Go

Learn. Practice. Build.

Home › Code Snippets › HTML Snippets › Reference › <a>

HTML Reference

<a> — The Anchor Element

The tag that made the web a web. Creates hyperlinks to pages, files, and locations.

Last updated: October 2026

Definition: The <a> element (anchor) defines a hyperlink — the core of the World Wide Web. It can link to external pages, internal routes, files, email addresses, phone numbers, or specific locations inside a page.

🎬 Live Example

Every link below uses only HTML attributes — no JavaScript.

💡 The same element handles every kind of link. Behavior is controlled by the href attribute.

📝

Basic Syntax

<a href="destination">Link text</a>

The href attribute is the only required attribute.

⚙️ Attributes Reference

Attribute Value Purpose
hrefURLThe destination. Required.
target_self, _blank, _parent, _topWhere to open the link.
relnoopener, noreferrer, nofollow, sponsoredRelationship to destination.
downloadfilename (optional)Download instead of navigating.
hreflanglanguage codeLanguage of the linked resource.
titletextTooltip text on hover.
referrerpolicyno-referrer, etc.Referrer info to send.
1

Basic External Link

Always add rel="noopener noreferrer" when using target="_blank".

<a href="https://example.com" target="_blank" rel="noopener noreferrer">
    Visit Example
</a>
2

Internal Link (Relative Path)

Links to another page on the same site.

<!-- Relative -->
<a href="./about.html">About Us</a>

<!-- Root-relative -->
<a href="/courses/python/">Python Course</a>
3

Fragment Link (Jump to Section)

Links to a specific element on the same page or another page.

<!-- Link to a section on this page -->
<a href="#attributes">Jump to Attributes</a>

<!-- The target -->
<h2 id="attributes">Attributes</h2>

<!-- Link to a section on another page -->
<a href="/docs/api.html#authentication">API Auth</a>
4

Email and Phone Links

Opens the user's email client or phone dialer. No JavaScript required.

<!-- Email with subject and body -->
<a href="mailto:hello@example.com?subject=Hello&body=Hi there">
    Send Email
</a>

<!-- Phone (uses device dialer on mobile) -->
<a href="tel:+15551234567">Call Us</a>

<!-- SMS -->
<a href="sms:+15551234567">Send Text</a>
5

Downloadable Files

The download attribute tells the browser to download instead of navigate.

<!-- Downloads the file -->
<a href="/files/guide.pdf" download>Download PDF</a>

<!-- Downloads and renames the file -->
<a href="/files/guide.pdf" download="html-guide.pdf">
    Download HTML Guide
</a>

💡 Note: download only works for same-origin URLs. Cross-origin downloads are blocked by browsers.

6

SEO Attributes — rel="nofollow" and rel="sponsored"

Tell search engines how to treat the link.

<!-- Don't pass SEO value to this link -->
<a href="https://unknown-site.com" rel="nofollow">
    Unverified Site
</a>

<!-- This is a paid or sponsored link -->
<a href="https://advertiser.com" rel="sponsored">
    Sponsored Link
</a>

<!-- Multiple values are allowed -->
<a href="https://example.com" rel="noopener noreferrer nofollow">
    External Link
</a>

🎯 Attribute Values Cheatsheet

target value Behavior
_selfSame tab (default).
_blankNew tab or window.
_parentParent frame.
_topTopmost frame.
rel value Meaning
noopenerPrevents window.opener access.
noreferrerNo referrer header. Implies noopener.
nofollowDon't pass SEO link juice.
sponsoredPaid/sponsored link.
ugcUser-generated content.

🎯 Anchor Target Section

You landed here because the "Jump to section" link at the top uses href="#example-anchor", which matched this section's id="example-anchor".

⚠️ Common Mistakes

♿ Accessibility Notes

❓ Frequently Asked Questions

What is the HTML <a> tag?

The <a> tag (anchor element) creates hyperlinks to other pages, files, locations within the same page, or any other URL. It is the defining feature of the World Wide Web.

What does the href attribute do?

The href attribute specifies the destination of the link. It can be a URL, an email address (mailto:), a phone number (tel:), a file download, or a fragment identifier (#section).

What is the difference between target="_blank" and target="_self"?

target="_blank" opens the link in a new tab or window. target="_self" opens it in the same tab (default). Always pair _blank with rel="noopener noreferrer" for security.

What does rel="noopener" do?

rel="noopener" prevents the new page from accessing the window.opener property of your page. This closes a security hole where the linked page could redirect your original tab to a phishing site.

How do I make an email link in HTML?

Use href="mailto:email@example.com". This opens the user's default email client with the address pre-filled. You can add subject and body with query parameters: mailto:email@example.com?subject=Hello&body=Hi

🎯 What's Next?

← All HTML Reference