- Instant help with your Html coding problems

Link to a section on the same page

Question:
How to link to a section on the same page?
Answer:
<a href="#chapter1">Chapter 1</a>
<a href="#chapter2">Chapter 2</a>
<a href="#chapter3">Chapter 3</a>

<div id="chapter1">
    <h1>Chapter 1</h1>
    <p>Lorem ipsum dolor sit ...</p>
</div>
<div id="chapter2">
    <h1>Chapter 2</h1>
    <p>Lorem ipsum dolor sit ...</p>
</div>    
<div id="chapter3">
    <h1>Chapter 3</h1>
    <p>Lorem ipsum dolor sit ...</p>
</div>
Description:

The HTML element (or anchor element), with its href attribute, creates a hyperlink to web pages, files, email addresses, locations on the same page, or anything else a URL can address. Content within each should indicate the link's destination.

To jump to a specific section on the same page just add a unique id attribute to the element where you want to jump and put this id prefixed with # as the href attribute of your link.

Share "How to link to a section on the same page?"
Tags:
jump to section, jump on the same page, link, fragment, navigation
Technical term:
Link to a section on the same page