CSS Specificity Calculator
Calculate CSS selector specificity as (a, b, c) per Selectors Level 4, including :is(), :not(), :has(), :where() and :nth-child(of S). Compare selectors side by side in your browser.
- Runs in your browser
- Tool input is not uploaded to ZeroTool servers
- Free · No Sign-Up
Scan with WeChat to share this tool
Examples, details and FAQ Worked examples, how it compares with other tools, and answers to common questions.
Reading the (a, b, c) Tuple
- a — ID: Each
#idselector adds 1 here. - b — Class / Attribute / Pseudo-class: Each
.class,[attr], or:pseudo-classadds 1. - c — Element / Pseudo-element: Each tag name or
::pseudo-elementadds 1. The legacy one-colon forms:before,:after,:first-lineand:first-letterare pseudo-elements too.
Compare left to right. The first column where two selectors differ decides which one wins. (1,0,0) always beats (0,99,99). If all three columns are equal, the rule that appears later in the stylesheet wins.
Common Examples
*→(0, 0, 0)p→(0, 0, 1).class→(0, 1, 0)#id→(1, 0, 0)#id .class:hover→(1, 2, 0)div > p + span::before→(0, 0, 4)a[href="#top"]→(0, 1, 1)— the#inside the quoted value is not an ID.
Functional Pseudo-classes
Selectors Level 4 §15 gives these pseudo-classes their own rules, and they are where hand counting usually goes wrong:
:is(.a, #b)→(1, 0, 0)— the most specific argument counts, even if the element matched.a.:not(.a, .b.c)→(0, 2, 0)— the arguments are compared, never added up.article:has(> img, > .figure)→(0, 1, 1):where(#app .card) p→(0, 0, 1)—:where()always counts zero, which is why reset and library styles use it.li:nth-child(2n+1)→(0, 1, 1)li:nth-child(2n+1 of .important)→(0, 2, 1)— one pseudo-class plus the most specific selector afterof.::slotted(span.note)→(0, 1, 2)and:host(.dark)→(0, 2, 0)— CSS Scoping adds the argument to the pseudo-element or pseudo-class.
Worked Examples
A component library ships :where(.btn) { color: gray } and your app adds .btn { color: navy }. Enter :where(.btn), .btn, .ui .btn to compare the three forms: (0, 0, 0), (0, 1, 0) and (0, 2, 0). The library rule loses to yours no matter which file loads last. If the library had written .ui .btn instead, you would need a second class or a cascade layer to override it.
A navigation link stays red on hover even though the active state sets it blue. Compare #nav a:hover and nav .nav-link.active: (1, 1, 1) against (0, 2, 1). The first column decides, so the ID wins even with fewer classes. Lowering the first rule to .nav a:hover would make it (0, 2, 1) as well, and then the later rule wins.
Pasting .card:not(.featured with the closing bracket missing gives an error card instead of a tuple: Missing ")" (position 10). Position 10 is the ( that is never closed; the browser would drop the whole rule.
Where Specificity Sits in the Cascade
CSS Cascade Level 5 §6 sorts declarations by origin and importance, then by context, then the style attribute, then cascade layer, and only then by specificity and order of appearance. A declaration marked !important or placed in a later @layer can beat a selector with a higher tuple. This tool calculates the specificity step only.
Limitations
- The nesting selector
&counts as zero here. In real CSS it has the specificity of the parent rule's most specific selector (CSS Nesting §4), which a single selector on its own does not show. - The tool checks the structure of the selector, not whether a pseudo-class name exists. An unknown name such as
:hovrstill counts as one pseudo-class, while a browser would drop the whole rule. - Inline styles,
!importantand@layerare outside the calculation, as described above. - Full-width characters such as
#,.and:are name characters in CSS, not#,.or:.#mainis one type selector,(0, 0, 1), and the card adds a note when it sees them. - The order inside a compound selector is not checked.
[x]pcounts as(0, 1, 1), although a browser rejects a type selector after an attribute selector.
An ideographic space (U+3000) or a no-break space (U+00A0) between two names does not make a descendant combinator. Chrome 152 reads it as part of a name (tested 2026-10-09 with document.querySelector() and the selectorText of an inserted rule), so div p is one type selector named "div p", (0, 0, 1), and it never matches a p inside a div. The tool counts it the same way and adds a note to the card. The specification differs: CSS Syntax 3 §4.2 defines whitespace as a newline, tab or space, and its list of non-ASCII name characters leaves out U+00A0 and U+3000 (it resumes at U+3001), so by the specification the selector is invalid.
Sources
FAQ
What is CSS specificity?
CSS specificity determines which style rule wins when multiple rules target the same element. It is expressed as a three-part tuple (a, b, c) where a counts ID selectors, b counts class/attribute/pseudo-class selectors, and c counts element type and pseudo-element selectors.
How is specificity calculated?
a = number of ID selectors (#id). b = number of class (.class), attribute ([attr]), and pseudo-class (:hover) selectors. c = number of element type (div, span) and pseudo-element (::before) selectors. The universal selector (*) and combinators (space, >, +, ~) contribute nothing.
How do I compare two selectors?
Enter both selectors separated by a comma. Commas inside :is(), :where() or an attribute value do not split the input. Compare the tuples column by column from the left; the first column that differs decides.
What about :not(), :is(), :has() and :where()?
:is(), :not() and :has() take the specificity of the most specific selector in their argument list, so :is(.a, #b) counts as (1, 0, 0). :where() always counts zero. :nth-child(An+B of S) counts one pseudo-class plus the most specific selector in S. These are the rules of Selectors Level 4 §15.
Does inline style or !important count?
No. Specificity is only one step of the cascade. Origin and importance (!important), cascade layers (@layer) and the style attribute are compared before specificity (CSS Cascade 5 §6), so this tool's result only decides between rules that tie on those steps.
Are my selectors sent anywhere?
No. The tuples are calculated in your browser, and the selectors are not sent or saved in browser storage. Analytics records only the tool name and an action: calc when you leave an edited input and all entered selectors parse successfully, and copy after a successful copy. Opening the page, typing alone, empty input and selector errors send no calc event. The selectors are not included in either event.