Skip to content

Menu

CSS Specificity Calculator

Calculate CSS selector specificity

Runs entirely in your browserFrontendFree, no sign-up
Loading tool

01What is CSS Specificity Calculator?

Two rules target the same element, and the one you expected to win doesn't. Nine times out of ten that is specificity. This calculator takes the selectors you paste and gives each one an (IDs, classes, elements) score, then ranks them strongest first with a bar for relative weight. Scoring follows the specificity section of the W3C Selectors Level 4 spec, plus CSS Scoping for :host and ::slotted. The tool walks the selector character by character. Each #id adds to the first column. Classes, [attribute] selectors and pseudo-classes such as :hover add to the second. Element names and pseudo-elements add to the third, including the old single-colon :before and :after forms. The functional pseudo-classes get special treatment, as the spec asks. :is(), :not() and :has() take the score of their single most specific argument. :where() always adds zero. :nth-child() with the "of S" syntax counts as one pseudo-class plus the strongest selector inside S. The universal selector and combinators add nothing. A worked example helps. Take div#main > ul.nav li:first-child a:hover. There is one ID (#main). There are three class-level parts: .nav, :first-child and :hover. The four element names are div, ul, li and a. So the result is (1, 3, 4). Now try :is(#a, .b) p. The :is() counts as its strongest argument, #a, so you get (1, 0, 1) even when the element really matched .b. Escaped names are handled too, so Tailwind's .hover\:bg-red:hover scores (0, 2, 0) instead of being misread as a pseudo-class. Paste a comma-separated list and each selector gets its own row, because browsers score them separately. Ranking compares column by column, so a hundred classes never outrank a single ID. Where it stops. The nesting selector & really takes its parent rule's specificity, but the tool can't see that parent, so & scores zero here. Inline styles and !important sit outside specificity altogether, so a footer note reminds you of them rather than scoring them. Specificity also only matters after origin and cascade layers are compared, and when two scores tie, source order decides. The scoring is a small parser running in the page. Your selectors aren't uploaded, and Copy just puts a ranked plain-text list on your clipboard.

Front-end developers and design-system maintainers use it to settle which of two conflicting CSS rules will win and why. The tool runs entirely in your browser, so your data never leaves your device.

02How to use CSS Specificity Calculator

  1. Type a selector into the first input, for example .card .title:hover.
  2. Click Add Selector to add more rows you want to compare.
  3. Read the IDs, Classes and Elements columns and the Specificity triple. The list is sorted from strongest to weakest.
  4. Remove a row with its delete button, or use the reset button to start over.
  5. Click Copy to take the ranked list as plain text.

03Worked examples

Input: div#main > ul.nav li:first-child a:hover
Result: (1, 3, 4)
Pseudo-classes like :first-child and :hover count in the class column, so this selector has three class-level parts (.nav, :first-child, :hover) and four type selectors.
Input: :is(#a, .b) p
Result: (1, 0, 1)
:is() takes the specificity of its most specific argument, so #a wins even if the element actually matched .b.
Input: :where(#x) .y
Result: (0, 1, 0)
:where() always adds zero, so the ID inside it contributes nothing.
Input: :not(.a, #b)
Result: (1, 0, 0)
:not() itself adds nothing; it counts as its most specific argument.
Input: li:nth-child(2 of .item)
Result: (0, 2, 1)
With the 'of S' syntax, :nth-child() counts as one pseudo-class plus the specificity of the selector after 'of'.
Input: .hover\:bg-red:hover
Result: (0, 2, 0)
The escaped colon is read as part of the class name, so only :hover counts as a pseudo-class.

04Common use cases

  • Working out why a Bootstrap or Tailwind component style isn't overriding a theme rule
  • Comparing two competing selectors during a CSS refactor before deleting one
  • Explaining the cascade to a junior developer with real selectors from your codebase
  • Checking whether a third-party widget's CSS will beat your own BEM classes
  • Deciding where :where() can lower specificity in a design-system reset stylesheet
  • Splitting a long comma-separated selector list to see which part is the heavy one

05Tips

  • Wrapping a selector in :where() is the cleanest way to ship low-specificity defaults that any user class can override.
  • The CSS nesting selector & takes the specificity of its parent rule, which this tool can't see, so it scores & as zero; score the expanded selector instead.
  • One ID outweighs any number of classes, which is a good reason to avoid ID selectors in shared stylesheets.
  • When two selectors tie, the one declared later in the stylesheet wins, so source order matters as much as the score.

06Related concepts

CSS cascade, Specificity, Pseudo-classes, :where(), !important, BEM.

Frequently Asked Questions

What is CSS Specificity Calculator?

CSS Specificity Calculator is a free, browser-based developer tool on AIDToolStack. Calculate CSS selector specificity It requires no installation or sign-up and works entirely in your browser.

Is CSS Specificity Calculator free to use?

Yes. No sign-up, no fees and no usage cap.

Does CSS Specificity Calculator store my data?

No. It runs in your browser; nothing is uploaded.

Cheat sheet

Reviews and commentsShow

Reviews

Sign in to leave a review.

Loading reviews…

Comments

Sign in to leave a comment.

Loading comments…

What changed in AI dev tools, once a month

Renames, shutdowns, pricing changes and new MCP setups, each with a source.

Subscribe