Example

A fragment link that reaches its section

Connect a meaningful link label to a unique section ID and inspect how fragment navigation behaves.

Beginner2 min readLearn · Practice · Review

Published by HTML Code Runner · AI-assisted material · Independent editorial review pending · Editorial policy

On this page

Understand the source

The href value #hours targets an element whose id is hours. The label tells the reader what information is ahead. The heading supplies both a navigation target and a useful section name. Changing only one of those matching values breaks the relationship.

<h1>Reading guide</h1>
<a href="#hours">Jump to opening hours</a>
<h2 id="hours">Opening hours</h2>
<p>Tuesday: 10:00–18:00</p>

Expected output

Activating the link moves to Opening hours inside the output document. Because this is an iframe, its fragment navigation belongs to the isolated result rather than the surrounding tutorial page. In a standalone page, the resulting fragment can also be copied as a direct link to the section.

Make a deliberate change

Add a second heading with id="membership" and a link labeled Read about membership. Activate both links with a keyboard. Then deliberately duplicate the hours ID on another element and inspect the markup in the diagnostic lab to understand why a plausible visual result is not sufficient.

Review the behavior

Use actual destination labels rather than Click here. Do not turn a page action into href="#" merely to make it look clickable. A link should navigate; a button should perform a local action. If a sticky header covers a target, reserve scroll space with CSS rather than changing the target ID.

Read the full explanation and expected output