Encodera

Thanks for reading!

Donate to the site — we work hard for you.

HTML & CSS reference

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

  • class — One or more classes of an element — the main way to reach it from CSS.
  • <label> — A label for a form field.
  • <a> — A link to another page, a file or a place on the page.

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.

Thanks for reading!

Donate to the site — we work hard for you.