More HTML: How to Create Links and Navigation in HTML

Join the AI Workshop to learn more about AI and how it can be applied to web development. Next cohort February 1st, 2026

The AI-first Web Development BOOTCAMP cohort starts February 24th, 2026. 10 weeks of intensive training and hands-on projects.


Links are fundamental to the web, connecting pages and enabling navigation.

Create links with the <a> (anchor) tag:

<a href="https://example.com">Visit Example</a>

Link to other websites:

<a href="https://google.com">Google</a>

Link to pages on your site:

<a href="/about">About Us</a>
<a href="/products/shoes">Shoes</a>

Link relative to current location:

<a href="./page.html">Same directory</a>
<a href="../other.html">Parent directory</a>

Link to a specific part of a page using the # symbol.

Linking to an ID

First, add an id to the target element:

<h2 id="features">Features</h2>

Then link to it:

<a href="#features">Jump to Features</a>

Same Page Navigation

<nav>
  <a href="#intro">Introduction</a>
  <a href="#features">Features</a>
  <a href="#pricing">Pricing</a>
</nav>

<section id="intro">...</section>
<section id="features">...</section>
<section id="pricing">...</section>

Linking to Another Page’s Section

<a href="/products#electronics">Electronics Section</a>

The # alone is often used as a placeholder:

<a href="#">Coming Soon</a>

Clicking this scrolls to the top of the page.

Use target="_blank":

<a href="https://example.com" target="_blank">Opens in new tab</a>

For security, add rel="noopener":

<a href="https://example.com" target="_blank" rel="noopener">Safe external link</a>

Force file download instead of navigation:

<a href="/files/report.pdf" download>Download Report</a>

Specify a filename:

<a href="/files/report.pdf" download="annual-report-2024.pdf">Download</a>

Note: Only works for same-origin files.

Email

<a href="mailto:hello@example.com">Email Us</a>

With subject and body:

<a href="mailto:hello@example.com?subject=Hello&body=I%20have%20a%20question">
  Email Us
</a>

Phone

<a href="tel:+15551234567">Call Us</a>
AttributePurpose
hrefURL destination
targetWhere to open (_blank, _self, etc.)
relRelationship to linked page
downloadDownload instead of navigate
titleTooltip text on hover

The rel Attribute

Common values:

<!-- Don't pass SEO value -->
<a href="..." rel="nofollow">User-submitted link</a>

<!-- Security for external links -->
<a href="..." rel="noopener noreferrer">External link</a>

<!-- Indicate sponsored content -->
<a href="..." rel="sponsored">Ad link</a>

Links have different states you can style with CSS:

a:link { color: blue; }      /* Unvisited */
a:visited { color: purple; } /* Visited */
a:hover { color: red; }      /* Mouse over */
a:active { color: orange; }  /* Being clicked */
  • Use descriptive text (avoid “click here”)
  • Indicate external links or downloads
  • Ensure sufficient color contrast
<!-- Bad -->
<a href="/report.pdf">Click here</a>

<!-- Good -->
<a href="/report.pdf">Download the annual report (PDF)</a>

Lessons in this unit:

0: Introduction
1: How to Use Semantic HTML Container Tags
2: ▶︎ How to Create Links and Navigation in HTML
3: How to Use Open Graph Meta Tags
4: How to Add Favicons to Your Website
5: Introduction to Web Accessibility