Boneyard Tools

CSS Specificity Calculator

Paste a CSS selector to see its specificity as the standard (a, b, c) triple and a single score. The breakdown shows exactly which IDs, classes, attributes, pseudo-classes and elements counted, so you can tell which rule wins.

How to calculate CSS specificity

  1. Type or paste a CSS selector such as #main .btn:hover.
  2. Read the (a, b, c) values: a counts IDs, b counts classes, attributes and pseudo-classes, c counts elements and pseudo-elements.
  3. Turn on compare mode to pit two selectors against each other and see which one would win.

Examples

ID, class and element

#id .class p
a=1, b=1, c=1, score 111

:not() counts its argument

p:not(.active)
a=0, b=1, c=1, score 11

Frequently asked questions

How is CSS specificity calculated?

Specificity is three numbers (a, b, c). a counts ID selectors like #id. b counts classes, attribute selectors like [type=text] and pseudo-classes like :hover. c counts element types and pseudo-elements like ::before. Compare a first, then b, then c; the higher value wins.

What does the score number mean?

The score is a flattened value, a times 100 plus b times 10 plus c, so a single selector is easy to compare at a glance. For everyday selectors it preserves the same order as the real cascade. When two selectors tie, the one declared later in the stylesheet wins.

How are :not(), :is() and :has() handled?

These functional pseudo-classes add no specificity themselves, but their argument does. The calculator adds the specificity of the most specific selector inside them. So :not(.x) counts as one class, and :is(#a, p) counts as one ID. :where() always adds nothing.

What about the universal selector and combinators?

The universal selector * and the combinators >, +, ~ and the descendant space add nothing to specificity. They affect what a selector matches but never how strongly it wins, so the calculator ignores them.

Where do inline styles fit in?

An inline style attribute, like style="color:red", beats any selector in a stylesheet. It is sometimes written as the (1,0,0,0) column ahead of IDs. Only !important or another inline style can override it, so this tool focuses on selector specificity, not inline styles.

Is my selector sent to a server?

No. The whole calculation runs in your browser with JavaScript. Nothing you type is uploaded or stored.

Related tools