CSS Specificity Calculator

Calculate CSS specificity and see exactly where it comes from. Enter one or more selectors and each is broken into labeled parts — IDs, classes and pseudo-classes, elements and pseudo-elements — with its (a, b, c) score, and the selector that wins is highlighted. Modern selectors like :is(), :not(), :has(), :where() and :nth-child(… of …) follow the current spec. It's free, runs in your browser, and nothing you paste is sent anywhere.

What counts where

Selector partAdds
#id(1, 0, 0)
.class, [attr], :hover(0, 1, 0)
div, ::before(0, 0, 1)
*, combinators, :where()(0, 0, 0)
:is(), :not(), :has()Most specific argument

When to use it

  1. Work out why a style isn't being applied.
  2. Compare two selectors before refactoring a stylesheet.
  3. Check that a :where() reset really has zero specificity.
  4. Teach how the cascade decides between competing rules.

How to Use

  1. Enter selectors, one per line or as comma-separated lists.
  2. Read each selector's (a, b, c) score and labeled parts.
  3. See which selector wins, or whether there's a tie.

Features

  1. (a, b, c) score with labeled parts
  2. Compare any number of selectors
  3. :is(), :not(), :has(), :where() per Selectors Level 4
  4. :nth-child(of S) support
  5. Handles quotes, escapes and nested lists
  6. 100% client-side

FAQs

How is CSS specificity calculated?

Count IDs into a, classes/attributes/pseudo-classes into b, and elements/pseudo-elements into c. Compare a first, then b, then c — the higher wins.

Do 11 classes beat one ID?

No. Columns never carry over: (1, 0, 0) beats (0, 11, 0).

What specificity does :not() or :is() have?

That of the most specific selector inside it. :where() is always zero, which makes it useful for overridable defaults.

What happens when specificity ties?

The rule that appears later in the stylesheet wins.

Where do inline styles and !important fit?

Inline styles beat any selector. !important declarations beat normal ones, including inline styles. Cascade layers are compared before specificity.

Is anything uploaded?

No. Selectors are parsed in your browser.

Technical Details

Specificity is a three-part weight, written (a, b, c) and compared column by column: a counts ID selectors; b counts classes, attribute selectors and pseudo-classes; c counts type selectors and pseudo-elements. The universal selector and combinators add nothing. The calculator tokenizes each selector itself rather than using a regex, so brackets, quoted attribute values and escaped characters don't confuse it, and selector lists are split only on commas at the top level. It follows Selectors Level 4 for the functional pseudo-classes: :where() always contributes zero; :is(), :not() and :has() contribute the specificity of the most specific selector in their argument list rather than counting as a pseudo-class; :nth-child(An+B of S) counts as one pseudo-class plus the most specific selector in S. The legacy single-colon pseudo-elements :before, :after, :first-line and :first-letter are counted as pseudo-elements. Each part is shown with what it adds, and the highest-specificity selector in the list is highlighted, with ties marked, since source order decides those.

Web & CSS Tools

Web & CSS Tools

  • CSS Color & Property Extractor
  • Responsive Breakpoint Cheatsheet
  • Google Fonts Pair Finder
  • CSS Clamp Generator
  • Fluid Type Scale Generator
  • CSS Flexbox Generator
  • CSS Grid Generator
  • CSS Border Radius Generator