HTML Id
Create a heading with an id and a link that jumps to it.
Understand the topic
An id uniquely identifies an element within a document. It can be a fragment destination, a label target, or a JavaScript lookup target. CSS id selectors start with #, although classes are often more reusable for styling. Use readable IDs and maintain uniqueness when repeating components or inserting content dynamically.
Worked example
<label for="student-name">Student name</label>
<input id="student-name" name="student_name" autocomplete="name">
The label for value matches the input id. The name attribute is separate: it identifies the field in submitted form data.
Practice
Create a heading with an id and a link that jumps to it.
Show a suggested answer
<a href="#opening-hours">Opening hours</a>
<h2 id="opening-hours">Opening hours</h2>Common mistake
Do not reuse an id on multiple fields. Duplicate IDs can break labels, fragments, and JavaScript selection.