Skip to content

Help us create more tutorials! Make a donation using the Donate button or become a member using the button below to hide this banner and track your progress.

Link to a specific section of your web page – HTML

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>

Link to specific section demo

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).

References

The Anchor element on MDN

Lesson tags: Open Lesson
Back to: HTML Course > HTML Links