CSS #id selector
- type
- selector
- applies to
- the single element carrying that id
- inherits
- n/a
- common values
- #header, #main-nav
Where it goes
For things there is only one of: the page header, a tag JavaScript also needs to find.
Example
#header {
background: black;
color: white;
}Common mistakes
- Using an id selector for anything reusable. Its high specificity makes it stubbornly hard to override from a class later.
- Using the same id on more than one tag. CSS will not complain, but ids must be unique, and JavaScript will only ever find the first one.