Demo
Summary
<a href="#last-section">Link text</a>
<!-- Other HTML code might be here -->
<h2 id="last-section">Header</h2>
Details
To create a link to a specific section of your web page, use an anchor element with the href
attribute and use the id
of another element on the page as the value (prefixed with a hash sign):
<a href="#last-section">Link text</a>
<!-- Other HTML code might be here -->
<h2 id="last-section">Header</h2>
It’s also possible to link to a specific section on a different page. For example, let’s say you have a page called about.html
and want to link to a specific section on it. You can do that like this:
<a href="about.html#last-section">Link text</a>
<h2 id="last-section">Heading</h2>
Exercises
Recreate the embedded CodePen demo by adding an anchor element to the HTML code. Then add an id attribute to the last heading (look for the comments for hints).
Using your text editor or CodePen, try creating a link to a specific section of your web page. (You will need to add a lot of text on the page in between the link and the element with the ID to see the effect work.)
References
The Anchor element on MDN