How do you create links to sections within the same page?
Give the section an id, and then link to it with href="#id". This is useful for a table of contents on a long page.
<a href="#html">HTML</a> | <a href="#css">CSS</a>
<h2 id="html">HTML</h2>
<p>HTML content...</p>
<h2 id="css">CSS</h2>
<p>CSS content...</p>
<a href="#top">Back to top</a>
- The id must be unique on the page.
- The link starts with
#followed by the id. - A link to
#top(or#only) takes the visitor to the top of the page.
To jump to a section of another page, see how to jump to a specific part of a page.
Learn more about the similar topics:
| Tutorials |
|---|
| HTML Links |
| HTML Images |
| Exercises & Assignments |
|---|
| Write an HTML program to create links (new tab and email) |
| Write an HTML program to display an image |