CSS Specificity Calculator
Paste a selector such as #nav .menu > li:hover and get its (a, b, c) score: IDs, then classes, attributes and pseudo-classes, then types and pseudo-elements. A comma-separated list is scored one selector at a time. To compare rules, put one selector per line in the second field: they are sorted by specificity, the winner is marked, and an exact tie goes to the later rule, as in the cascade. Text that does not parse as a selector is reported with the position of the problem instead of being scored. In current browsers, a selector that parses but that the browser does not recognize is still scored, with a note.
How to Use This Tool
- Enter a Selector. Type one in Enter CSS Selector. It starts with
#nav .menu > li:hover. Every selector in a comma-separated list gets its own card with an (a, b, c) score. - Read the Score. a counts IDs, b counts classes, attributes and pseudo-classes, and c counts types and pseudo-elements. Scores are compared left to right, so (1,0,0) beats (0,99,99).
- Compare Rules. Put one selector per line in Or Enter Multiple Selectors (one per line). Results are sorted from most to least specific and the top one is marked WINS. When two are equal, the one that comes later in your stylesheet wins and the tie is stated.
- Fix Errors. A line that does not parse as a selector is reported with its line and character position, and the other lines are still scored. Clear All empties both fields.
How specificity is counted, and what it ignores
Specificity is three separate counts compared left to right, not one number. IDs go in a, classes, attributes and pseudo-classes in b, types and pseudo-elements in c. The universal selector * and combinators add nothing. That is why .button (0,1,0) loses to #app .button (1,1,0) however late it appears. Inline styles beat every selector, and !important and cascade layers are decided before specificity is compared at all.
:is(), :not() and :has() take the specificity of their most specific argument, so a:is(#x, .y) is (1,0,1) even when the element only matches .y. :where() always adds zero. :nth-child(2 of .x) is one pseudo-class plus the most specific selector after of. Pseudo-elements count as types, including the older single-colon :before and :after. In nested CSS, & takes the specificity of the parent rule, which this tool cannot see, so it adds nothing to the score and a note says so. Chromium does not drop an invalid entry inside :is() or :where() that contains &: it keeps it as written and counts it as one pseudo-class, and the score does the same, with a note.
The calculator reads selectors with the Selectors Level 4 grammar. Quoted attribute values like [href="a]b,c#d"], escapes like .\31 0 and namespaces like svg|a are handled, text that does not parse is rejected, and inside :is() and :where() an entry that does not parse, or that your browser rejects, is ignored with a note, as browsers do. A namespace prefix counts as declared, since the tool cannot see your @namespace rules. The tool never looks at a document, so a valid selector may still match nothing.