id
A unique identifier of an element on the page.
Syntax
<section id="contacts">…</section>Examples
An anchor link to a section of the page:
<p><a href="#contacts">Jump to contacts</a></p>
<p style="height: 120px;">Long text…</p>
<h2 id="contacts">Contacts</h2>
<p>hello@example.com</p>Linking a label and a field:
<label for="phone">Phone</label>
<input id="phone" type="tel">Notes
An id value must be unique on the page and contain no spaces. It is used for anchors, linking a <label> to a field, ARIA attributes and JavaScript. For styling, classes are better: an #id selector is very specific and hard to override.
See also
Related recipes
In the tutorial
- Attributes — How HTML attributes work, the global attributes id, class, title, lang, hidden and style, boolean attributes and data attributes.