Module lessons (3/4)
Links, Navigation & URL Paths
Links Are the Glue of the Web
The H in HTML stands for HyperText—text wired together by clickable <a href="..."> anchors. Unlike <button> elements (which trigger in-page actions like submitting a form or opening a modal), an <a> element navigates somewhere with a URL.
| Link Pattern | Use Case | Example |
|---|---|---|
| Relative path | Subpage inside current folder | <a href="pricing.html">Pricing</a> |
| Root-relative path | Route anchored from domain root / | <a href="/docs/intro">Docs</a> |
| Absolute URL | External domain | <a href="https://developer.mozilla.org">MDN</a> |
| Fragment anchor | Jump directly to an element id on the page | <a href="#faq">Jump to FAQ</a> |
| Safe external new tab | Opens safely without window.opener access | <a href="https://example.com" target="_blank" rel="noopener noreferrer"> |
Example 1 — Navigation List & Same-Page Anchor
Wrapping navigation links inside <nav> with an unordered list gives screen reader users a clean landmark and a count of links ("navigation, list, 3 items"):
<nav aria-label="Primary">
<ul>
<li><a href="/">Home</a></li>
<li><a href="/courses">Courses</a></li>
<li><a href="#contact">Jump to Contact</a></li>
</ul>
</nav>
<section id="contact">
<h2>Contact</h2>
<p>Write to <a href="mailto:hello@example.test">hello@example.test</a>.</p>
</section>Example 2 — Never Write "Click Here"
Screen reader users often pull up a flat list of every link on the page out of context. Calling every link "Click here" or "Read more" turns that list into guesswork.
<!-- Vague: useless when listed alone -->
<p>To check holiday shipping dates, <a href="/shipping">click here</a>.</p>
<!-- Descriptive: clear in any context -->
<p>Check our <a href="/shipping">2026 holiday shipping schedule</a>.</p>Step 1 — Wire a descriptive external link safely
Update the anchor so it links to 'https://web.dev' safely with target='_blank' and rel='noopener noreferrer', and replace 'Click here' with descriptive text mentioning 'Web.dev performance guides'.
Show hint
Add rel="noopener noreferrer" to the <a> tag and change the link label from "Click here" to "Read the Web.dev performance guides".
Solution available after 3 attempts
Step 2 — Connect a page Table of Contents with fragment anchors
Wire the two navigation links using href='#overview' and href='#pricing', and add matching id attributes on the two <section> tags.
Show hint
Change href="#" to href="#overview" and href="#pricing", and set id="overview" / id="pricing" on the matching sections.
Solution available after 3 attempts
Step 3 — Build a skip link + header navigation bar
Add an anchor href='#main-content' labeled 'Skip to main content' before <nav>, add links to '/docs' and '/blog' inside <nav>, and give <main> id='main-content'.
Show hint
Add <a href="#main-content">Skip to main content</a> above <nav>, wrap Documentation and Engineering Blog in <a> links with "/docs" and "/blog", and add id="main-content" to <main>.
Solution available after 3 attempts
You are inside '/courses/html/intro.html'. Where does a link with href='/about' navigate versus href='about'?
What happens for keyboard users if you omit the href attribute from an <a> tag?
<a class="nav-btn">Open Dashboard</a>