Frontend ToolsA little help for every day

Search by name or task, such as JSON or percentage.

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.

View all tools
ResultUpdates as you type
RankSelectorSpecificity (A, B, C)
1main.content #hero .button:hover(1, 3, 1)
2#nav li.active > a[href](1, 2, 2)
4:where(.card) p::first-line(0, 0, 2)
3.btn:not(.primary, #submit)(1, 1, 0)

Compare A first, then B, then C – there is no carrying over. If two are equal, the rule that comes later wins.

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.

  1. Paste your selectorsEnter one per line. Comma lists are split, and anything from an opening brace onwards is ignored.
  2. Read the scoresEach selector gets (A, B, C): IDs; classes, attributes and pseudo-classes; types and pseudo-elements.
  3. 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.

Often Used Together

Next step

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 tools