Give a heading a name with id, then link to it with a
Long pages such as Wikipedia articles open with a list of contents, and every entry jumps down the page to its part.
A link can go to another page, or to a place on the same page. On a long page, a menu of links at the top lets people jump straight to the part they want.
Make your prediction first. Help opens once you've locked it in.
<header>
<h1>Chess club</h1>
<nav>
<ul>
<li><a href="#results">Results</a></li>
<li><a href="#join">Join</a></li>
</ul>
</nav>
</header>
<main>
<section>
<h2>When we meet</h2>
<p>Wednesdays at lunch in room 4. Bring a board if you have one.</p>
</section>
<section>
<h2 id="results">Results</h2>
<p>The Owls won the autumn ladder. The Hawks came second.</p>
</section>
<section>
<h2 id="join">Join</h2>
<p>Come to room 4 on Wednesday and ask for a game.</p>
</section>
</main>
Read the code. The menu links look like links you know, but their href values are new. Someone clicks Results. What does the page do?
Compare the page with your prediction. Click each link in the menu, then scroll back up. Find the name that appears in both a link and a heading.
| Code | What it does | Why |
|---|---|---|
<h2 id="results"> |
Gives this heading the name results |
id is an attribute, like href. The name marks a place on the page, and changes nothing you can see |
<a href="#results"> |
Jumps to the element named results |
The # means "on this page". Without it, the browser looks for another page called results |
| the same name in both places | Joins the link to its place | The names must match exactly, capitals too. If nothing has that id, the link does nothing |
| each id used once | Keeps every name pointing at one element | A link can only jump to one place, so two elements with one id means it goes to the first |
the links in a <nav> |
Makes the menu for a long page | Part names and a menu go together: <nav> holds the links, each part has an id |
<header>
<h1>Chess club</h1>
<nav>
<ul>
<li><a href="#results">Results</a></li>
<li><a href="#join">Join</a></li>
</ul>
</nav>
</header>
<main>
<section>
<h2>When we meet</h2>
<p>Wednesdays at lunch in room 4. Bring a board if you have one.</p>
</section>
<section>
<h2 id="results">Results</h2>
<p>The Owls won the autumn ladder. The Hawks came second.</p>
</section>
<section>
<h2 id="join">Join</h2>
<p>Come to room 4 on Wednesday and ask for a game.</p>
</section>
</main>
Two parts share one name.
<ul>
<li><a href="#join">Join</a></li>
</ul>
<h2 id="join">Join the club</h2>
<p>Come on Wednesday.</p>
<h2 id="join">Join the chess ladder</h2>
<p>Put your name on the list.</p>
One link in the menu does not jump.
Rules and Join jump down the page, but clicking Results tries to open a different page. Click the line that causes it.
Give the When we meet heading the id meet. Nothing changes on the page yet.
id is an attribute, so it goes inside the opening tag of the heading.
Write <h2 id="meet"> for the When we meet heading.

Add a menu item that jumps to meet. Click it to test.
Copy one of the menu items and change its words to When we meet.
The address is the id with a # in front: href="#meet".

Name the title top, and add a link at the bottom of the page that jumps back to it.
Give the <h1> the id top, then add a paragraph at the bottom with a link to #top.
Write <a href="#top">Back to the top</a> inside a <p>.

Give the When we meet heading the id meet.
This ticks when your page has all of the above.
Add a menu link to the meet heading.
This ticks when your page has all of the above.
Add a link at the bottom that jumps back to the top.
This ticks when your page has all of the above.
This mixes the last lessons: the parts of a page, and a list of links.
Put the lines in order to make a header with the title and, inside a nav, a list of two links. One line is not needed.
This page has three parts but no menu. Add a <nav> with a list of three links under the title, inside the <header>. Each link jumps to one of the headings: give them the ids rules, results and join.
Give each heading an id of its own. Then add the <nav> with a list of links under the title.
Each link is <a href="#rules">, with the same name as the id, and the # in front.
Click each link to test it. A link that does nothing has a name that does not match.

Add a nav in the header with three jump links, and give the three headings the ids rules, results and join.
This ticks when your page has all of the above.
Students name a place on a page with id and link to it with href="#name", so a menu can jump to each part of a long page. About 40 minutes.
Open the teacher guide: answers, solutions, slides and a worksheet.
Do the Make task yourself (about 5 minutes).
An id is an attribute that gives one element a name. A link whose href starts with # goes to the element with that name on the same page. The # is the whole difference between "this page" and "another page". Pages need to be long enough to scroll, or the jump is invisible: make the preview small or add a paragraph.
Matching the name in the href and the id exactly, and remembering the # in the href only. Have them click every link to test it.
Stretch: Add a fourth part with its own id and menu link, and a link at the bottom of the page that jumps back to the top (give the heading an id).
Support: Give students the Make starter with the ids already added, and ask them only to build the nav and the links.
Next lesson uses id again: a form label points at its box by id, so clicking the label finds the box. Class idea: find a long page (a Wikipedia article) and look at how its contents list jumps down the page.