Encodera

Thanks for reading!

Donate to the site — we work hard for you.

HTML & CSS reference

#id

Selects the single element with the given `id` attribute.

Syntax

#name { … }

Parameters

ParameterTypeDescription
#nameidThe element with `id="name"`.

Examples

An id has higher specificity than a class, so its color wins:

<style>
  #main-title { color: crimson; }
  .title { color: gray; }
</style>
 
<h2 id="main-title" class="title">The id wins over the class</h2>

Notes

An id must be unique on the page. Its specificity is so high that overriding it later is hard, so for styles prefer classes, and keep ids for anchor links, <label for> and JavaScript.

See also

  • .class — Selects elements that have the given class in the `class` attribute.
  • :target — Matches the element whose `id` equals the fragment in the address after `#`.
  • id — A unique identifier of an element on the page.

In the tutorial

  • Selectors — How to pick elements for styling — by tag, class, id, nesting and attribute.

Thanks for reading!

Donate to the site — we work hard for you.