yigityalim
projectshandbookslabshireshare
xgithub
siteprojectshandbookslabschangelog
aboutusesnowhireshare
elsewherexgithublinkedinemail
metarssllms.txtsitemap
© 2026 Yiğit Yalım. All rights reserved.
/
Back to Labs
May 10, 2026·web

CSS Specificity Calculator

Paste two selectors, see the (a, b, c) tuple, learn which one wins. Token-by-token color breakdown. Correctly handles `:where()`, `:not()`, `:is()`, and `:has()`.

css · specificity · selectors

PreviousColor Contrast (WCAG)NextCubic-Bezier Tester

Most devs get specificity wrong — and reach for !important. This lab compares two selectors and shows which one wins, with the math broken down per token.

CssSpecificity — (id, class/attr/pseudo, element)
A022
nav.primary·>·a:hover
B101
#site-header·a
B kazanır — (1,0,1)Not: !important selector specificity'yi geçersiz kılar ve ayrı bir cascade katmanında değerlendirilir.
#id → (1,0,0).class / [attr] / :pseudo → (0,1,0)element / ::pseudo → (0,0,1):where() → (0,0,0)

What does (a, b, c) mean?

Three counts, compared left to right:

  • a — number of ID selectors (#header)
  • b — classes, attributes, pseudo-classes (.btn, [type=text], :hover)
  • c — elements and pseudo-elements (div, ::before)

#header (1, 0, 0) > .btn.large.primary (0, 3, 0) > nav a:hover (0, 1, 2). Compare a first; ties decide on b, then c.

Spec gotchas

  • :where() contributes 0 specificity. Modern CSS's best feature — :where(.theme-dark) .btn stays at the same specificity as a bare .btn, so users can still override.
  • :not(), :is(), :has() take the specificity of their highest argument. :is(#x, .y) = (1, 0, 0) because #x wins.
  • Inline style="..." ranks above all selectors (only !important beats it).
  • !important skips specificity entirely — among rules of the same importance, specificity decides.

Practical advice

  • Avoid the specificity arms race — keep selectors as flat as possible
  • Use :where() for resets and theming so users can override without escalating
  • !important only for third-party overrides (analytics widget, Tailwind class)
  • BEM (.block__elem--mod) enforces single-class rules — no war to begin with