Skip to main content

CSS Specificity Calculator

Calculate the specificity of any CSS selector as (inline, ID, class, element) notation. Compare two selectors to see which one wins the cascade. Supports pseudo-classes, pseudo-elements, attribute selectors, :not(), :is(), :where(), and combinators.

✓ Inline, ID, class, element breakdown ✓ Compare two selectors ✓ :not / :is / :where support ✓ 100% browser — no server
.nav #logo:hover
0Inline
1ID
2Class/Attr
0Element
(0,1,2,0)

Score: 10200

Specificity Scoring Rules

0,1,0,0ID selectors#header, #nav
0,0,1,0Class / attribute / pseudo-class.btn, [type], :hover
0,0,0,1Element / pseudo-elementdiv, p, ::before
0,0,0,0Universal selector*, combinators

Try an example

Frequently Asked Questions

What is CSS specificity?▼

CSS specificity is the algorithm browsers use to determine which CSS rule applies when multiple rules match the same element. It is represented as a 4-part value (inline, ID, class, element). Higher specificity wins. When two selectors have equal specificity, the one declared later in the stylesheet wins (the cascade).

How is CSS specificity calculated?▼

Specificity is calculated as four separate columns: (inline, ID, class, element). Inline styles = 1,0,0,0. ID selectors (#foo) = 0,1,0,0. Class selectors (.foo), attribute selectors ([type='text']), and pseudo-classes (:hover) = 0,0,1,0. Element selectors (div, p) and pseudo-elements (::before) = 0,0,0,1. Combinators (+, ~, >, space) and the universal selector (*) contribute 0.

Which selector wins: .nav a vs nav a.link?▼

.nav a has specificity (0,0,1,1) — one class + one element. nav a.link has specificity (0,0,1,2) — one class + two elements. nav a.link wins because (0,0,1,2) > (0,0,1,1). Specificity is compared column by column from left to right; a tie in one column is broken by the next.

Does !important override specificity?▼

Yes. !important overrides the normal specificity algorithm entirely — an !important declaration always wins against a non-!important declaration, regardless of specificity. However, if two competing declarations both use !important, specificity is compared again. Using !important excessively makes CSS hard to maintain; prefer increasing specificity or restructuring your selectors.

What is the specificity of :not()?▼

The :not() pseudo-class itself contributes 0 to specificity, but its argument does count. For example, :not(.active) has specificity (0,0,1,0) because .active is a class selector. The same applies to :is() and :has() — the most specific argument within them is counted.

Why does :where() have zero specificity?▼

:where() was specifically designed to have zero specificity for all its arguments. This is useful for writing base styles or resets that you want to override easily without increasing specificity. Unlike :is() or :not(), :where(h1, h2, h3) always contributes (0,0,0,0).

Share this tool: X / Twitter LinkedIn
✓ 60,000+ developers use DevPlaybook ★★★★★ 4.8 / 5 on Gumroad ✓ MIT licensed · Instant download ✓ No login required

Related Products

on Gumroad

You Might Also Need

More Free Tools

Enjoying this tool? Get more like it.

Weekly developer tool guides, productivity playbooks & AI tricks. Free. No spam.

DevPlaybook Pro 7 days free

Unlock AI-Powered Dev Tools

  • ⚡ AI Code Review, Doc Generator & SQL Builder
  • ⚡ All premium templates & early access
  • ⚡ Member discounts on Gumroad products
Start Free Trial →

$9/mo after trial · Cancel anytime

Want the full toolkit?

Get DevPlaybook Pro

Every template, guide, boilerplate, and automation script in one bundle. 13 premium products — grab them all at once and save big.

$79
$241 separately Save $162 (67% off)
Get DevPlaybook Pro — $79 →

MIT licensed · Instant download · No subscription

See what's included → Browse all deals →