All tools Developer

CSS Specificity Calculator

Calculate the (a, b, c) specificity of CSS selectors and sort them by weight.

Runs in your browser. Nothing you open or type here is uploaded.

How to use

  1. Enter CSS selectors, one per line.
  2. Click Calculate.
  3. Read the table: each selector's (a, b, c) counts, its weight and the parts that contributed.
  4. Compare the rows — the results are sorted by specificity.

Details

Specificity decides which of two matching CSS rules wins. Each selector is scored as a tuple: a counts ID selectors, b counts classes, attribute selectors and pseudo-classes, and c counts type selectors and pseudo-elements. The columns compare left to right, so (1, 0, 0) beats (0, 10, 0) no matter how large the later columns grow. Functional pseudo-classes follow their own rules: :is(), :not() and :has() take the specificity of their most specific argument and add nothing themselves, while :where() always contributes zero. The universal selector and combinators add nothing either.

  • The weight number is only a shorthand. The tuple decides: one ID outranks any number of classes.
  • This tool scores selectors only. Inline styles outrank every selector, and !important outranks normal declarations regardless of specificity.
  • Legacy single-colon pseudo-elements such as :before count in the c column, exactly like ::before.

Common questions

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

:is(), :not() and :has() take on the specificity of their most specific argument — the pseudo-class itself adds nothing. :where() always contributes zero, no matter what's inside it.

Why does one ID beat ten classes?

Specificity compares the (a, b, c) tuple left to right, like version numbers: (1, 0, 0) always beats (0, 10, 0) because the a column is compared first. The weight number shown is just a handy shorthand.

Does the universal selector * count?

No. * (and combinators like > or +) add nothing to specificity. Pseudo-elements such as ::before count in the c column, as do legacy single-colon forms like :before.

What about inline styles and !important?

Inline styles beat any selector, and !important beats normal declarations regardless of specificity. This tool only scores selectors themselves.