Ad – 728Γ—90
🌐 Beginner

HTML Links – The Anchor Tag

Links are what make the web a web. The <a> (anchor) tag creates hyperlinks β€” the most fundamental interactive element in HTML. Every navigation menu, every "Read more" button, every back-link is an anchor tag. This lesson covers every type of link you'll use.

⏱️ 14 min read🎯 BeginnerπŸ“… Updated 2026

Basic Link Syntax

HTML
<!-- Basic link structure -->
<a href="https://ylearner.org">Visit ylearner</a>
<!--  ↑ tag   ↑ destination        ↑ link text  -->

<!-- The href (Hypertext REFerence) attribute is the URL -->
<!-- The content between tags is the clickable text -->
HTML
<!-- 1. External link (absolute URL) β€” opens same tab -->
<a href="https://github.com">GitHub</a>

<!-- 2. External β€” opens NEW tab (target="_blank") -->
<!-- ALWAYS add rel="noopener noreferrer" for security -->
<a href="https://github.com" target="_blank" rel="noopener noreferrer">
  GitHub (new tab)
</a>

<!-- 3. Internal link β€” same site, relative path -->
<a href="about.html">About</a>
<a href="../index.html">Up one folder</a>
<a href="/contact.html">Absolute path from root</a>

<!-- 4. Jump link β€” scroll to element with matching id -->
<a href="#pricing">Jump to Pricing</a>
<!-- Somewhere on the page: -->
<h2 id="pricing">Pricing Plans</h2>

<!-- 5. Email link -->
<a href="mailto:hello@example.com">Email us</a>
<!-- Pre-fill subject and body: -->
<a href="mailto:hello@example.com?subject=Hello&body=I%20wanted%20to%20say...">
  Email with subject
</a>

<!-- 6. Phone link (tappable on mobile) -->
<a href="tel:+447700900000">+44 7700 900000</a>

<!-- 7. Download link -->
<a href="/files/report.pdf" download>Download Report</a>
<!-- Custom filename: -->
<a href="/files/report-2026.pdf" download="annual-report.pdf">Download</a>
Ad – 336Γ—280

Relative vs Absolute Paths

Path typeExampleWhen to use
Absolute URLhttps://example.com/page.htmlExternal sites only
Root-relative/about.htmlInternal links β€” reliable across folders
Relative../images/photo.jpgInternal links relative to current file
⚠️
Security: always use rel="noopener noreferrer" with target="_blank"

Without rel="noopener", the opened page can access your page via window.opener β€” a security vulnerability called "reverse tabnapping". Always add rel="noopener noreferrer" when opening external links in new tabs.

HTML
<!-- Wrap any element in <a> to make it clickable -->
<a href="https://ylearner.org" aria-label="ylearner homepage">
  <img src="/assets/logo.png" alt="ylearner logo" width="120">
</a>

πŸ“‹ Summary

  • <a href="url">text</a> β€” the anchor tag creates a hyperlink.
  • target="_blank" opens in a new tab β€” always pair with rel="noopener noreferrer".
  • Use root-relative paths (/page.html) for internal links β€” most reliable.
  • Fragment links (#id) jump to elements with matching id on the same page.
  • href="mailto:" opens email client. href="tel:" dials on mobile. download triggers file download.