specificity

The weight the browser gives a CSS selector, used to decide which rule wins when two set the same property.

In more detail

An ID selector outweighs a class, which outweighs an element name. When specificity is equal, the rule that appears later in the stylesheet wins. Utility-class systems keep specificity flat, which is why tools such as tailwind-merge remove conflicting classes instead of relying on order.

Example

In the browser: Scores are compared column by column: one ID beats any number of classes. nav.menu a.active scores 0-2-2. Rising specificity to win conflicts leads to specificity wars, which cascade layers and :where() help avoid.

Related terms

Taught in

References