#id
Selects the single element with the given `id` attribute.
Syntax
#name { … }Parameters
| Parameter | Type | Description |
|---|---|---|
| #name | id | The 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
In the tutorial
- Selectors — How to pick elements for styling — by tag, class, id, nesting and attribute.