CSS Specificity Calculator

Find out why a CSS rule is not applying: compare the specificity of your selectors and see which one wins.

FreeNo sign-upPrivate — runs in your browser
SelectorAIDsBclassesCelementsSpecificity

How to use the CSS Specificity Calculator

  1. Type your selectorsEnter one selector per line, or a comma-separated list. Anything after { is ignored, so you can paste whole rules.
  2. Read the scoreEach selector gets three numbers: A (IDs), B (classes, attributes and pseudo-classes) and C (elements and pseudo-elements), with a breakdown.
  3. Find the winnerThe highest specificity is highlighted. Compare A first, then B, then C; on a tie, the rule written last wins.

Example

#nav .menu li a:hover has 1 ID, 2 classes/pseudo-classes and 2 elements: (1, 2, 2). It beats header nav > ul li.active a at (0, 1, 5), because IDs count first.

:where(.card) h2 scores just (0, 0, 1), because :where() always adds zero; :is(#main, .content) p:first-child scores (1, 1, 1), taking its most specific argument.

Frequently asked questions

How is specificity calculated?

Count IDs for A, classes, attribute selectors and pseudo-classes for B, and element names and pseudo-elements for C. Compare A first; only if A is equal compare B, then C. 1 ID beats any number of classes.

How do :is(), :not() and :has() count?

They take the specificity of their most specific argument. :where() is special: it always counts as zero, which makes it useful for easy-to-override default styles.

What about inline styles and !important?

Inline style="" attributes beat every selector. !important beats normal declarations, and between two !important declarations specificity decides again. Use !important rarely.

Popular posts from this blog

Character Counter

Speech to Text Online

Keyboard Tester