Skip to content

Try our new Crash Courses!

Buy one of our new Crash Courses, now hosted on Teachable.

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 Reference > HTML Links