Report

Help us improve this tool

CSS Specificity Calculator

Calculate the specificity of any CSS selector and compare multiple selectors side by side. See the inline, ID, class, and element breakdown, ranking, and which rule wins a conflict.

O M T

What the CSS Specificity Calculator Does

The CSS Specificity Calculator reads every selector you paste and breaks its weight into the classic three part score: IDs, classes, and elements. Each selector gets its own (a, b, c) signature and a numeric score, the list is ranked from strongest to weakest, and the top selector is highlighted so you can see at a glance which rule wins a conflict. Everything runs in your browser, so internal class names and application structure never leave the page.

Specificity is the tie breaker browsers use when two rules target the same element with conflicting declarations. When styling misbehaves and a rule seems to be ignored, the cause is almost always a selector with a higher specificity somewhere else in the stylesheet. Scoring selectors by hand is error prone, especially with functional pseudo-classes like :is(), :not(), and :where(), which follow rules of their own.

How to Use the Calculator

  1. Paste one selector per line into the input box. Lines can also contain comma separated selector lists, and each selector is scored separately.
  2. Read the breakdown for each row: IDs count toward a, classes, attributes, and pseudo-classes toward b, and elements and pseudo-elements toward c.
  3. Use the ranking to see which selector wins. The highlighted card shows the strongest selector and its signature.
  4. Use the Sample button to reload a set of examples and try your own from there.

How Specificity Is Counted

  • ID selectors: every #id adds 1 to the first column, the highest weight in a selector.
  • Classes, attributes, and pseudo-classes: .class, [type="text"], and :hover all add 1 to the second column.
  • Elements and pseudo-elements: a tag name like div, ::before, and legacy single colon pseudo-elements like :first-line add 1 to the third column.
  • The universal selector and combinators: *, >, +, ~, and whitespace add nothing at all.

The columns never carry over: no number of class selectors can outweigh a single ID, and no pile of element selectors beats a single class. That is why this tool reports the score as a triple and only uses the numeric form, a times 100 plus b times 10 plus c, as a convenient way to sort and compare.

Functional Pseudo-Classes

Modern CSS adds a twist to the counting. The :where() pseudo-class always contributes zero, no matter how heavy the selector inside it is, which makes it perfect for resets and defaults that are easy to override. The :is(), :not(), and :has() pseudo-classes contribute the specificity of their most specific argument, so :is(.a, #b) counts like an ID. :nth-child() counts as a pseudo-class plus the selector after its "of" keyword, such as :nth-child(2n + 1 of .card) adding a class on top.

Specificity, Source Order, and Layers

Specificity is only one part of the cascade. When two rules have exactly the same specificity, the one that appears later in the source wins, which is why import order matters in large stylesheets. Inline styles beat every selector, and an !important declaration jumps above all of them (while also being the hardest thing to maintain). CSS cascade layers provide an explicit override order that ignores specificity entirely, so a rule inside a later layer wins even if its selector is weaker. The key rule to remember is that layers are resolved before specificity is even consulted.

Keeping Specificity Manageable

  • Prefer single class selectors. They all share the same (0,1,0) weight, so conflicts come down to source order instead of arms races.
  • Avoid styling with IDs. One ID outweighs any number of classes and usually means a refactor later.
  • Use :where() for base and reset styles so consumers can override them with a single class.
  • Keep selector depth shallow. Long descendant chains are brittle when markup changes.
  • Reach for cascade layers when you need a predictable order between resets, components, and utilities.

To keep the stylesheet tidy after the audit, run it through the CSS Beautifier or the CSS Minifier, and when a selector still will not apply, test it live with the CSS Selector Cheat Sheet as a reference. If the conflict comes from utility classes, the CSS to Tailwind Converter can help translate the rule.

Frequently Asked Questions

What is CSS specificity?

Specificity is the weight a browser assigns to a selector when deciding which conflicting declaration to apply. It is expressed as a three part tuple of IDs, classes (including attributes and pseudo-classes), and elements (including pseudo-elements).

How is the numeric score calculated?

The tool packs the triple into one number with a times 100 plus b times 10 plus c. It is a convenient way to sort and compare, but the real comparison is always the three columns in order, since the columns never carry over.

What happens when two selectors have equal specificity?

The rule that appears later in the stylesheet wins, commonly called source order. The tool flags ties so you know the decision comes down to where the rules are written.

How do :is(), :not(), and :has() affect specificity?

They take the specificity of their most specific argument. For example, :not(.a, #b) counts exactly like #b, because the ID argument is the heaviest part of the list.

Why does :where() not add any specificity?

:where() is defined to always contribute zero, by design. That makes it ideal for resets, base styles, and default themes, because a single class in user code can override them without fighting weight.

Do inline styles and !important participate in specificity?

They are not selectors, so they sit outside the specificity comparison. Inline styles beat any selector, and !important declarations beat inline styles. Both are best used sparingly because they are hard to override later.

How do cascade layers change the outcome?

Rules inside a later cascade layer win over earlier layers regardless of specificity. Layers are resolved first, so two rules with wildly different weights can be decided purely by the layer they were declared in.