Skip to content
BEAD

CSS Specificity Calculator

Score one or more CSS selectors and see which one wins the cascade.

Selectora (IDs)b (cls/attr/pc)c (type/pe)Score
#nav .item a:hover1211, 2, 1
.btn.primary0200, 2, 0
ul li0020, 0, 2
:is(h1, .heading)0100, 1, 0
:where(.foo)0000, 0, 0
[type="text"]0100, 1, 0
nav > ul li.active a::before0150, 1, 5

How specificity works

CSS specificity is a 3-tuple (a, b, c) compared left-to-right:

  • a — ID selectors (#id)
  • b — class, attribute, and pseudo-class selectors (.cls, [attr], :hover)
  • c — type and pseudo-element selectors (div, ::before)

:not(X) and :is(X) take the maximum specificity of their arguments; :where(X) always contributes zero. *and combinators don't count. Inline styles beat selectors; !important beats everything except a later !important.

You might also like