How specificity works
When two rules target the same element, the browser picks the more specific one. Specificity is counted as three numbers (a, b, c):
- a — number of ID selectors (
#header) - b — number of class, attribute (
[type=text]) and pseudo-class (:hover,:nth-child()) selectors - c — number of type (
div) and pseudo-element (::before) selectors
Compare left to right: (1,0,0) beats (0,5,0); (0,2,0) beats (0,1,3). The universal selector *, combinators (> + ~) and :where() add nothing.
Modern selectors
:is()/:has()— count the most specific argument inside them.:where()— always zero specificity (that's its superpower).:not()/:is()/:has()— count the most specific selector list inside them (e.g.:not(#x)adds an ID).:nth-child()and similar An+B pseudo-classes count as one pseudo-class.!important— overrides normal specificity entirely; equal-importance ties fall back to source order.- Inline styles beat any selector (except
!important), and are outside this model.
Practical takeaway
If a style "isn't applying", the almost-always cause is specificity — your other rule has a higher (a,b,c). The calculator shows you the numbers so you can decide: raise yours (add a class or ID), or lower theirs (use :where() to zero out a wrapper selector).
Edge cases and hard limits
selectorList() splits a comma-separated selector into individual selectors, and specificity() scores each one as a triple: id count, class/attribute/pseudo-class count, element/pseudo-element count. cmp() compares those triples lexicographically, balanced() handles nested parentheses, and ident() finds identifier boundaries so a class name inside an attribute string is not miscounted. Pseudo-classes that take a selector argument use the highest specificity inside them.
Formats, sizes and other limits
Specificity is one input to the cascade, not the whole story. !important, source order, inheritance, cascade layers, inline styles and shadow boundaries all override or bypass it, and none are modelled here. A selector list produces several scores but the page cannot tell you which one wins, because that needs the DOM and the declaration order.
Privacy: processed in your browser
Selectors are scored as text in this tab. The page cannot read your stylesheets, and nothing you paste is sent.
Frequently asked questions
Why is my rule not applying?
Specificity may not be the reason. Check for !important, load order, @layer precedence, or a selector that simply does not match.
Do selectors inside :not() count?
Yes. They are scored normally and the highest inside the parentheses is added to the outer selector.
How do inline styles compare?
Inline styles beat any selector except one marked !important. This tool scores selectors only.