CSS Specificity Calculator
Compute (id, class, type) specificity for any selectors and see why a rule wins.
Selectors
Ranked specificity
Type CSS selectors to rank their specificity
Results update as you type. Nothing leaves your browser.
What actually wins the cascade
Specificity only compares selectors within the same cascade origin. An inline style attribute beats any selector, and !important declarations beat normal ones from the same origin — in order: transitions, user-agent !important, user !important, author !important, animations, normal author styles. Inside author styles, earlier @layer declarations lose to later layers, and unlayered styles beat layered ones.
Never convert specificity to a "score" like a×100 + b×10 + c: 11 classes (0, 11, 0) still lose to one id (1, 0, 0). The columns are compared one at a time, not summed. If a rule doesn't apply, check the selector matches at all, then origin, layers, !important, and finally source order.
Details
The CSS Specificity Calculator parses any number of selectors — one per line or comma-separated — and computes each one's (id, class, type) specificity triple exactly as browsers do per Selectors Level 4. Classes, attribute selectors and pseudo-classes add to the middle column; type names and pseudo-elements add to the last; ids add to the first; `*` and combinators count nothing. Functional pseudo-classes follow the current spec: :is(), :not() and :has() take their most specific argument, :where() contributes nothing, and the :nth-child(An+B of S) form adds the most specific selector in S. Selector lists split correctly inside parentheses, so grouped rules like `h1, h2` and arguments like :is(#a, #b) are never shredded; comments, at-rule lines and declaration blocks from pasted CSS are stripped automatically. Escaped framework selectors (.\31 0, .w-1\/2), legacy pseudo-elements (:before) and shadow parts (::part, ::slotted) are handled with informational notes. Invalid selectors — dangling combinators, unclosed brackets or parentheses — are flagged with the error position and excluded from the ranking instead of silently miscounted. Everything runs in your browser; nothing is uploaded.
More examples
Resolve an override war
Ranked side by side: (1, 2, 0) beats (0, 1, 4) because the id column wins first — exactly why your .active style loses.
Understand functional pseudo-classes
:is() takes its most specific argument for (1, 1, 0); :where() contributes nothing, leaving (0, 0, 1).
Check what you need to beat
Compare the incumbent against a proposed override to see which column you must strengthen to win.
Examples
Why the override loses
#nav .item:hover
div ul li a.active(1, 2, 0) vs (0, 1, 4)The id column decides immediately — no amount of type selectors catches up with a single id.
:is() takes the max, :where() takes nothing
:is(#a, .x.y.z) p(1, 0, 1)Arguments contribute their most specific member (1, 0, 0), not their sum — and :where() would add zero.
Framework selectors with escapes
.\31 0 .w-1\/2(0, 2, 0)Escaped Tailwind-style class names are read as single classes, not broken at the backslashes.
About this tool
The CSS Specificity Calculator computes the exact (id, class, type) specificity triple for any selectors you paste, exactly the way browsers compare them per the Selectors Level 4 specification. Each selector is tokenized in place: ids (#nav) fill the first column, classes, attribute selectors and pseudo-classes (.item, [type="text"], :hover) fill the second, and type names plus pseudo-elements (div, ::before) fill the third. Universal selectors (*) and combinators (>, +, ~, descendant space) count nothing — and the tool says so explicitly instead of guessing.
Functional pseudo-classes follow the current spec, which is where most hand calculations go wrong. :is(), :not() and :has() contribute the specificity of their most specific argument — never the sum — while :where() always contributes (0, 0, 0) no matter how heavy its arguments look. The :nth-child(An+B of S) form counts as one pseudo-class plus the most specific selector in S, and plain :lang(), :dir() and :nth-child(2n+1) add a single class-column point. Argument lists are split paren-aware, so grouped rules like `h1, h2` and arguments like :is(#a, #b) are never shredded at their commas.
Every ranked row can be expanded into a per-token breakdown: each counted piece appears as a chip labeled with its column (id, class, type) and its contribution, so "why (1, 2, 0)?" is answered token by token rather than by a black-box number. Shadow-DOM selectors are surfaced honestly — ::part() counts as a pseudo-element and ::slotted(sel) adds its argument — and legacy single-colon pseudo-elements like :before are counted correctly with a modernization hint.
Invalid selectors don't poison the ranking. A dangling combinator (`div >`), an unclosed bracket or parenthesis, or a stray character is flagged with its position and excluded, while the valid selectors around it are still ranked — mixed pastes from real stylesheets keep working. Comments, at-rules and declaration bodies from pasted CSS are stripped automatically, and everything computes locally in your browser: no selector ever leaves the tab.
What this tool does not do
- Specificity is only one cascade input — origin, @layer order, !important and source order decide outcomes this tool deliberately explains statically rather than simulates.
- ::part() is counted as one pseudo-element per the CSS Scoping model; browsers may resolve parts differently across nested shadow trees.
- Very large lists are capped (2,000 selectors / 200k characters) and the table shows the first 200 rows to stay responsive.
How to use this tool
Paste your selectors
Enter one selector per line or separate them with commas. Comments, at-rules and declaration blocks from pasted CSS are ignored automatically.
Read the ranked list
Valid selectors are sorted best-first with competition-style ranks; ties share a rank and keep their input order.
Expand a row
Click any selector to see each token as a chip labeled with its column and contribution — including :is()/:has() arguments and their triples.
Copy the comparison
Use the copy button to grab the ranking as a markdown table for code review, issues, or teaching notes.
Use cases
Debugging override wars
Paste the incumbent rule and your proposed replacement to see exactly which column loses and what needs strengthening.
Teaching the cascade
Expand any row to show students which tokens counted and why :is(), :where() and :not() behave differently.
Auditing third-party CSS
Paste a vendor stylesheet's selectors wholesale — comments and declaration bodies are stripped, and malformed selectors are flagged with positions instead of silently miscounted.
How the (a, b, c) columns fill
| Selector piece | Column |
|---|---|
| #nav | a — ids |
| .item, [type="text"], :hover, :is(...) | b — classes, attributes, pseudo-classes |
| div, ::before, ::part(x) | c — types and pseudo-elements |
| * | nothing |
| >, +, ~, descendant space | nothing |
| :where(anything) | nothing (always 0, 0, 0) |
| :is/:not/:has(args) | most specific argument, never the sum |
Columns compare left to right: (1, 0, 0) beats (0, 99, 99). There is no carrying or total score.
Common mistakes
Mistake:Converting specificity to a score like a×100 + b×10 + c.
Fix:The columns compare one at a time with no carrying: (0, 11, 0) loses to (1, 0, 0). Eleven classes never beat one id.
Mistake:Summing :is() argument specificities.
Fix::is(), :not() and :has() take their single most specific argument. :is(#a, .b.c) is (1, 0, 0), not (1, 2, 0).
Mistake:Treating an inline style or !important as a specificity number.
Fix:They live outside selector specificity entirely: inline styles beat any selector, and !important beats normal declarations from the same origin regardless of the triple.
Frequently asked questions
How is CSS specificity calculated?
Each selector becomes a triple (a, b, c). a counts id selectors like #nav; b counts classes, attribute selectors and pseudo-classes like .item, [type="text"] and :hover; c counts type names and pseudo-elements like div and ::before. Combinators (>, +, ~, descendant space) and the universal selector * count nothing. When two selectors compete, the columns compare left to right: (1, 0, 0) beats (0, 99, 99), and there is no carrying between columns — which is why converting specificity to a "points" score like a×100 + b×10 + c is wrong.
Do pseudo-classes count as classes?
Yes — every pseudo-class (:hover, :focus-visible, :nth-child(2n+1), :lang(en)…) adds 1 to the class column. Pseudo-elements (::before, ::after, ::placeholder) instead add 1 to the type column, and legacy single-colon forms like :before are still pseudo-elements. Functional pseudo-classes have extra rules: :is(), :not() and :has() take the specificity of their most specific argument, and :where() always contributes (0, 0, 0) regardless of its arguments.
What specificity does :is(), :not() or :has() have?
The specificity of the single most specific selector in its argument list — never the sum. :is(#a, .b.c) contributes (1, 0, 0), and :has(> #x .y) contributes (1, 1, 0). :where() is the exception: it always contributes nothing, which is exactly why it exists for styling third-party or low-priority markup. The tool expands each argument with its own triple so you can see which one won.
Does inline style beat ID? Does !important beat everything?
An inline style attribute beats any selector, including ids — specificity numbers simply don't apply to it. !important beats normal declarations from the same origin, again regardless of specificity. But the full order is: transitions, then !important declarations by origin (user-agent, user, author), then animations, then normal author styles, where layered styles lose to later layers and unlayered styles win. So an author !important in an early @layer can lose to a normal unlayered rule in some comparisons — the tool's education card walks through the order.
How do @layer and source order affect which rule wins?
Specificity only compares selectors that already tie on everything before it: same origin, same !important status, and same cascade layer. Later @layer declarations beat earlier ones, and unlayered author styles beat layered ones — even if the layered selector has a higher triple. Source order breaks the last remaining ties: among equal-specificity selectors in the same layer, the one declared last wins. Use this tool to compare selector math, then check layers and order in your stylesheet.
Why is my malformed selector not ranked?
Selectors the browser would reject are excluded so they can't silently miscount: a dangling combinator like `div >`, an unclosed bracket or parenthesis, or a stray character is flagged with its position and an explanatory hint, while the valid selectors around it still rank. Paste mistakes like comments, at-rules and declaration bodies are stripped automatically, so copying straight from a stylesheet works.
References & standards
Related tools
.env Secret Safety Linter
Validate .env syntax and spot likely leaked credentials or placeholder secrets.
.gitattributes Generator
Build .gitattributes rules for line endings, Git LFS, GitHub linguist marks and merge drivers — with a one-line explanation for every rule.
.htaccess Generator
Build an Apache .htaccess — HTTPS redirects, rewrites, error pages, security headers, and basic auth
2D Fluid Dynamics & Particle Physics Sandbox
A physics playground with two engines sharing one canvas. The fluid mode runs a real Eulerian Navier-Stokes solver — semi-Lagrangian advection, explicit diffusion, Jacobi pressure projection and vorticity confinement — that you paint with dye and velocity using mouse or touch. The particle mode is a damped Verlet N-body engine with gravity wells, Coulomb attractors and repulsors, spring links, wall restitution and elastic circle collisions. Particle counts adapt to the device (100k target on WebGL2 desktop, 2k-5k on CPU fallback), and every configuration exports as runnable code: a Matter.js world, a PixiJS ticker setup, or a standalone vanilla Canvas engine.
A/B Test Sample Size Calculator
Compute required sample size per variant and test duration from baseline conversion rate, minimum detectable effect, alpha and power.
ABA Routing Number Validator
Validate 9-digit US ABA routing numbers with 3-7-1 Mod-10 breakdown.