Frontend Tools
CSS Specificity Calculator
Calculate CSS selector specificity as (A, B, C) following Selectors Level 4, with :is(), :not(), :has() and :where() rules, and rank several selectors at once.
How to use CSS Specificity Calculator
Enter one selector per line; comma-separated lists are split into separate selectors. A single selector shows its A, B and C counts, while several are ranked in a table from the highest specificity to the lowest.
- Paste your selectorsEnter one per line. Comma lists are split, and anything from an opening brace onwards is ignored.
- Read the scoresEach selector gets (A, B, C): IDs; classes, attributes and pseudo-classes; types and pseudo-elements.
- Compare the rankingWith several selectors the table ranks them; equal scores share a rank, and then the later rule wins.
How specificity is counted
A counts ID selectors, B counts classes, attribute selectors and pseudo-classes, and C counts type selectors and pseudo-elements. The universal selector * and combinators such as > and + count nothing. So main.content #hero .button:hover scores (1, 3, 1), #nav li.active > a[href] scores (1, 2, 2), and :where(.card) p::first-line scores (0, 0, 2). In .btn:not(.primary, #submit), :not() takes its most specific argument, #submit, giving (1, 1, 0). Scores are compared column by column with no carrying, so (0, 20, 0) still loses to (1, 0, 0).
The tricky pseudo-classes
:is(), :not() and :has() add nothing themselves but take the highest specificity in their argument list, so :is(#a, .b) span is (1, 0, 1). :where() always adds zero, which makes it handy for low-priority defaults. :nth-child(2n+1 of .item) counts as one pseudo-class plus the selector after of, so li:nth-child(2n+1 of .item) is (0, 2, 1). Pseudo-elements like ::before, and the legacy single-colon :before, count in C. The nesting selector & takes its parent's specificity, which the tool can't see, so it is left out and a note says so.
Accuracy and data handling
After adding generated code to a project, test it in the target browsers and responsive sizes. The calculation runs in your current browser; the tool code does not send the input to a processing API.
FAQ
How is CSS specificity compared?
Compare A first; if equal, compare B, then C. The higher one wins. When all three are equal, the rule that appears later in the stylesheet applies.
Where do !important and inline styles fit?
Neither is part of selector specificity. Inline style attributes beat any selector, !important declarations beat normal ones, and cascade layers are weighed before specificity. The calculator scores selectors only.
Why can't any number of classes beat one ID?
Specificity is compared column by column without carrying over. Twenty classes give (0, 20, 0), which is still lower than (1, 0, 0) because the ID column is compared first.
More Frontend Tools
Related toolsGenerate CSS transition code with easing presets, a curve preview and reduced-motion CSS.
Build responsive CSS grid columns with auto-fit, auto-fill or a fixed count, previewed live.
Shrink HTML by removing comments and spare whitespace, with the byte saving shown.
Strip comments and whitespace from JavaScript safely, with the size saving shown.
Indent messy or minified HTML into readable, nested lines, including inline CSS and JS.
Unminify CSS into tidy, indented rules with one declaration per line.