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
- CSS cascade — The CSS process that decides which of several competing rules sets a property on an element.
- tailwind-merge — A JavaScript library that removes Tailwind classes overridden by later ones in the same list, such as dropping p-4 when px-6 follows.
- CSS — The language that describes how web pages look: colours, fonts, spacing, layout and animation.
- CSS selector — A pattern, such as .card, #menu or nav a, that picks which elements a CSS rule applies to or which elements a DOM query returns.
- ID selector — A CSS selector that matches the one element with a given id attribute, written with a hash such as #menu.
- class selector — A CSS selector that matches elements with a given class name, written with a dot such as .card.
- type selector — A CSS selector that matches every element with a given tag name, such as button or p.
- cascade layer — A named group of CSS rules, declared with @layer, whose priority in the cascade is set by layer order instead of selector specificity.
Taught in
- Tailwind CSS v4 Engine: CSS Variables & Theme Extensions — Design Systems & Component Engineering
- Class Variance Authority: Type-Safe Variant & Prop Orchestration — Design Systems & Component Engineering
- Storybook & Component Driven Development Workflows — Design Systems & Component Engineering
- CSS Parsing, The CSSOM And The Render Tree — Frontend Architecture & Web Platform
- The Cascade Algorithm: Specificity, Inheritance And Source Order — Frontend Architecture & Web Platform
- CSS Cascade Layers: Taming Specificity Wars with @layer — Frontend Architecture & Web Platform
- Modern Selectors: :has(), :is(), :where() And Nesting Standards — Frontend Architecture & Web Platform