Lesson 18 of 51 · Module 3, lesson 3 of 6 · 3 min
Links to a place on the same page
Let readers jump to a section of a long page, and back to the top.
What you'll learn
- How to link to a section of the same page
- How to make a "Back to top" link
- How to link to a section of another page
Why this matters
On a long page, readers want to jump straight to the part they need: the ingredients, the steps, the questions. A short list of links at the top — like a table of contents — saves them from scrolling, and helps keyboard users too.
Two steps
- Give the target an
idattribute: a name that is unique on the page. - Link to it with
#and the same name.
<p><a href="#steps">Go to the steps</a></p>
<h2 id="steps">Steps</h2>
A complete example
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Tomato soup</title>
</head>
<body>
<h1 id="top">Tomato soup</h1>
<p>Jump to: <a href="#ingredients">Ingredients</a> · <a href="#steps">Steps</a></p>
<h2 id="ingredients">Ingredients</h2>
<p>Six tomatoes<br>One onion<br>One litre of water<br>Salt</p>
<h2 id="steps">Steps</h2>
<p>Cut the tomatoes and the onion.</p>
<p>Cook them in the water for twenty minutes.</p>
<p>Blend the soup and add salt to taste.</p>
<p><a href="#top">Back to top</a></p>
</body>
</html>
What you'll see: two links under the title. Clicking Steps jumps down to the Steps heading. Back to top jumps up again. (On a short page, the jump is small, because there is little to scroll.)
Rules for id values
- Unique: no two elements on one page may have the same
id. - No spaces: use hyphens, such as
id="serving-ideas". - Lower case, to match your file-name habit.
idvalues are case-sensitive:#Stepsdoes not findid="steps". - The
#goes in the link only, not in theiditself.
Linking to a section on another page
Put the page's path first, then # and the id:
<a href="soup.html#steps">See the soup steps</a>
Try it yourself
- Select the complete example and choose Try it. Click the jump links in the preview.
- Add a new section, "Serving ideas", with
id="serving", and add it to the "Jump to" line. - Break it on purpose: change the link to
href="#Serving". It stops working, because the case does not match.
Common mistakes
- Forgetting the
#in the link, such ashref="steps". The browser looks for a file calledsteps. Fix:href="#steps". - Putting
#in theid, such asid="#steps". Fix:id="steps". - Two elements with the same
id. The link jumps to the first one only. Fix: everyidis unique. - Different spelling or case between the link and the
id. Fix: copy the name exactly.
Check yourself
- Which attribute marks the place to jump to?
- Write a link that jumps to
id="faq"on the same page. - Write a link to the section
id="steps"on the pagesoup.html.
Answers
id.<a href="#faq">Questions</a>(any clear link text).<a href="soup.html#steps">Soup steps</a>.
Next: your pages have text and links. Now add pictures — and learn to describe them for people who cannot see them.

