Section links make long pages easier to browse. A table of contents can list the important headings near the start of the article. The important question is always where the link leads and whether the person reading the page can predict it.
What You Need to Know
Let links point to actual headings with stable IDs. Keep link text close to the heading text so readers know what they will find.
Links are the pathways through a website. The words on a link should help someone choose where to go before clicking it.
Example: See It in Action
Add this example to the appropriate part of a practice HTML page. Read each line before you open the page in your browser.
This is a short HTML fragment. To try it as a webpage, put it inside the body element of a complete HTML document.
<nav aria-label="On this page">
<a href="#intro">Introduction</a>
<a href="#materials">Materials</a>
</nav>
<section id="intro">
<h2>Introduction</h2>
</section>
<section id="materials">
<h2>Materials</h2>
</section>
Let’s Understand the Example
- An a element becomes a working link when it has an href. Its visible text should tell readers where they will go.
- Nav identifies a major collection of navigation links.
- Section groups content around a shared topic and usually has a heading.
- Aria-label supplies an accessible name when a visible label is unavailable or inadequate.
- Href contains the destination of a link. A value starting with # points to an id on the same page.
- Id gives one element a unique name within the page, so a link, label, or script can point to it.
The first example link points to #intro. Check whether that destination exists relative to the document. A link changes where readers go; it does not perform an action such as saving a form.
What Should You See?
You should see a link named “Introduction”. Selecting it leads to #intro when that destination exists. Try it with the mouse and the keyboard.
Imagine this link is read out of context. Would its text still explain the destination? Rename unclear links before trying to make them look nicer with CSS.
Try It Yourself
- Add a third section and include it in the contents menu.
- Save your changes, open or refresh the page, and compare the result with the original example.
- Tell a friend what your change did. If you are not sure, undo it, refresh the page, and compare.
Common Beginner Mistakes
- Using different labels for a contents link and its heading without a clear reason.
- Avoid dead links, empty href values and clickable-looking text without a real destination.
Key Takeaways
- Section links make long pages easier to browse.
- An a element becomes a working link when it has an href. Its visible text should tell readers where they will go.
- Let links point to actual headings with stable IDs. Keep link text close to the heading text so readers know what they will find.