CSS: ID selector (#)

By Xah Lee. Date: . Last updated: .

match ID attribute's value

tag#val

match the value of a attribute id

same as

tag[id="val"]

tag is optional. It can be a simple selector (selecting by tag name, id, class etc) or a compound selector (combination of tag name, id, class etc). If empty, it means the universal selector (* any tag).

🟢 TIP: normally you don't need the tag, because ID attribute should be unique on a page. There is only one element with a given ID value.

#x2795 {
 border: solid 1px grey;
}

CSS. Selectors

Selector types
Simple selectors
Combinators
Selector list
Nesting syntax
Special selector
Misc