CSS Specificity Calculator
CSS specificity determines which style rule the browser applies when multiple rules target the same element. Specificity is calculated as a three-part value (a, b, c) where a counts ID selectors, b counts class, attribute, and pseudo-class selectors, and c counts type and pseudo-element selectors. A selector with higher 'a' always beats one with higher 'b' or 'c', regardless of quantity: a single ID selector (1,0,0) beats any number of classes. This calculator parses your CSS selector and shows the specificity breakdown. You can also compare two selectors side by side to see which one would win in a specificity conflict.
CSS specificity rules
| Selector type | Column | Example | Specificity |
|---|---|---|---|
| ID selector | a | #header | (1,0,0) |
| Class selector | b | .nav | (0,1,0) |
| Attribute selector | b | [type="text"] | (0,1,0) |
| Pseudo-class | b | :hover, :first-child | (0,1,0) |
| Type selector | c | div, p, h1 | (0,0,1) |
| Pseudo-element | c | ::before, ::after | (0,0,1) |
| Universal selector | none | * | (0,0,0) |
Common examples
| Selector | Specificity |
|---|---|
| * | (0,0,0) |
| p | (0,0,1) |
| .nav | (0,1,0) |
| #header | (1,0,0) |
| ul li | (0,0,2) |
| .nav .item | (0,2,0) |
| #header .nav a:hover | (1,2,1) |
CSS specificity: frequently asked questions
What is CSS specificity?
CSS specificity is the algorithm browsers use to determine which CSS rule to apply when multiple rules target the same element. It is expressed as a three-part value (a, b, c) where: a = number of ID selectors, b = number of class, attribute, and pseudo-class selectors, c = number of type (element) and pseudo-element selectors. The selector with the highest specificity wins. If specificities are equal, the last declared rule wins (cascade order).
How is CSS specificity calculated?
Count three categories in the selector: (a) ID selectors (#id): each adds 1 to the 'a' column. (b) Class selectors (.class), attribute selectors ([attr]), and pseudo-classes (:hover, :nth-child): each adds 1 to the 'b' column. (c) Type selectors (div, p, h1) and pseudo-elements (::before, ::after): each adds 1 to the 'c' column. The :not(), :is(), :has(), and :where() pseudo-classes have special rules: :not() and :is() take the specificity of their most specific argument; :where() contributes zero specificity.
Does !important override specificity?
Yes. A declaration with !important overrides any specificity value. If two conflicting declarations both have !important, then specificity rules apply again between those two. The !important rule is powerful but considered poor practice: it breaks the natural cascade and makes debugging harder. It is better to increase specificity by adding a more specific selector.
What specificity does inline style have?
Inline styles (style='...') have a specificity higher than any selector combination except !important. They are represented as (1, 0, 0, 0) in the four-column specificity model that includes inline styles. In the three-column model (a, b, c), inline styles effectively have 'infinite' a value and always beat any selector-based rule.
What is the universal selector's specificity?
The universal selector (*) has zero specificity (0, 0, 0). The same applies to combinators (+, >, ~, space, ||) and the :where() pseudo-class: they all contribute zero to specificity. A declaration with no selectors (though not valid CSS) would also have zero specificity.
Official sources
- W3C CSS Selectors Level 4: Specificity rules specification.
- MDN Web Docs: CSS Specificity reference.
Reviewed by the CalculatorHub team, edited by James Graham, 14 June 2026. See our methodology.