CSS Specificity Calculator

Calculate and compare the specificity weight of CSS selectors to debug styling conflicts.

Results

How it works

CSS specificity is a three-part weight (a, b, c) the browser uses to decide which rule wins the cascade. a counts ID selectors, b counts classes, attributes and pseudo-classes, and c counts type selectors and pseudo-elements. The universal selector * and combinators (>, +, ~, space) contribute nothing. Selectors are compared left-to-right: higher a always beats lower a, then b, then c. Inline styles and !important override everything. Functional pseudo-classes like :not() and :is() add the specificity of their most-specific argument, while :where() contributes zero.

Frequently asked questions

How is CSS specificity calculated? ▾
The browser builds a three-part tuple (a, b, c): count the IDs (a), then classes + attributes + pseudo-classes (b), then element names + pseudo-elements (c). Compare tuples left-to-right — a selector with more IDs always beats one with fewer, regardless of classes or elements.
Why is my CSS rule not being applied? ▾
Another rule with higher specificity is overriding yours, or the earlier rule has !important. Paste both selectors into this calculator to compare their weights, then either increase specificity (e.g. add a class) or reorganize your cascade so the desired rule wins.
Do pseudo-classes like :hover count the same as classes? ▾
Yes. Pseudo-classes (:hover, :nth-child, :focus) add to the middle b value just like a class selector. Pseudo-elements (::before, ::after) add to c instead — the same level as element names like div or p.

Related tools