HTML chapters

Chapter 6 of 17

Relative paths and fragment links

Try this in our HTML Compiler →

The idea

HTML has no arithmetic or logical operators. Link addresses are a more useful foundation: a relative path is resolved from the current document, a leading slash starts at the site's root, and a fragment beginning with # targets an element id. Use real destinations when publishing a page.

Worked example

<a href="#practice">Jump to practice</a>
<section id="practice">
  <h2>Practice</h2>
  <p>Build a page with two sections.</p>
</section>

What to check

The fragment link stays in the document and targets the section. The id must match exactly. A fragment is navigation, not a condition or comparison.

Practice task

Add a second section and a link to it. Check that the two links lead to different sections.

Check your understanding

Explain the result in your own words before changing the example. Change one thing at a time, compare the result with your prediction, and keep the version that demonstrates the concept clearly.

Try it yourself

Output
Ctrl/Cmd+Enter runs · Ctrl/Cmd+S downloads the project · Local auto-save is always on