Free CSS Specificity Calculator: Find Out Why Your CSS Rule Is Not Applying
Paste any CSS selector and instantly see its specificity as (a, b, c) per CSS Selectors Level 4. Handles :is(), :not(), :has(),:where(), attribute selectors, pseudo-elements, and combinators correctly. Compare two selectors side-by-side to see which wins.
IDs (a)
0
Classes (b)
3
Elements (c)
0
Breakdown
Selectors Level 4 Spec
Returns specificity as (a, b, c) triple per the modern CSS Selectors Level 4 spec. Correctly handles :is(), :not(), :has() (max of args), and :where() (always 0).
Compare Mode
Paste two selectors and see which wins by spec — and by how much. Useful for diagnosing "why is the wrong rule winning" bugs.
Token Breakdown
Each part of the selector is colored and labeled (ID / class / attribute / pseudo-class / pseudo-element / element / combinator) so you see exactly where the weight comes from.
100% Client-Side
All parsing runs in your browser via custom JavaScript — no fetch, no signup. Works offline once loaded.
Why Your CSS Rule Is Not Applying — And How To Fix It
When a CSS rule does not apply, the cause is almost always specificity. Some OTHER rule has higher (a, b, c) values and is winning the cascade. The fix is rarely !important — it is usually understanding the relative weight of your selectors. Our Free CSS Specificity Calculator parses any selector you paste and shows the breakdown: how many IDs, how many classes/attributes/pseudo-classes, how many elements. Plus a compare mode that puts two competing selectors side-by-side so you can see exactly which wins and by how much.
Pair this with our CSS Beautifier (clean up the stylesheet before debugging), CSS Minifier (compress for production), Color Contrast Checker (verify accessibility once the cascade resolves), Flexbox Generator and Grid Generator (visual layout playgrounds for the styles whose specificity you are computing here).
CSS Specificity Rules — What Counts & What Does Not
| Selector Part | Weight Added | Notes |
|---|---|---|
| Inline style (style attribute) | (1, 0, 0, 0) — beats every selector | Per spec, inline style is a separate dimension above selectors. CSS-in-JS often emits it. |
| ID selector (#id) | adds 1 to "a" | IDs are heavy — avoid using them in stylesheets when classes will do. |
| Class (.cls) | adds 1 to "b" | Workhorse selector. Stack two classes (.btn.btn) to outweigh a single class without raising ID count. |
| Attribute ([type="text"]) | adds 1 to "b" | Same weight as a class — useful for form-state styling without classes. |
| Pseudo-class (:hover, :focus) | adds 1 to "b" | Includes :is(), :has() which inherit max specificity of arguments. |
| Element (div, span) | adds 1 to "c" | Lightest — most selectors involve at least one element name. |
| Pseudo-element (::before) | adds 1 to "c" | Same weight as element. Double-colon syntax is modern; single-colon is legacy alias. |
| * universal selector | adds 0 to all | Pure noise for specificity — only useful for cascading effects. |
| Combinators (>, +, ~, space) | 0 | Direction/relationship, not weight. Do not affect specificity. |
| :where(X) — special | 0 | Argument specificity is DISCARDED. Use :where to opt out of specificity wars. |
| :is(X) / :not(X) / :has(X) | takes MAX of argument specificity | Lets you express alternatives without inflating beyond the heaviest alternative. |
Five Common Specificity Problems & Fixes
1. Style not applying
Compute specificity of the rule you want vs the rule that won. Whichever has higher (a, b, c) wins. Bump yours by adding a class, NOT an ID.
2. Two rules with same specificity
CSS uses source order: whichever appears LATER in the stylesheet wins. Reorder or use a more specific selector.
3. !important war
Avoid !important except for utility classes (e.g. .hidden { display: none !important }). One !important beats specificity; two !importants compete by specificity.
4. Inline style wins everything
Inline style="..." beats every stylesheet selector except !important. Move to a class-based rule or use :is() to lift cascade weight.
5. Component styles stomping app
Wrap library/component styles in :where(.lib) — specificity contributes 0, so app rules always win.
Four Specificity Best Practices for 2026
1. Keep Specificity Flat
Aim for (0, 1, 0) or (0, 2, 0) for most rules — one or two classes. Component-driven CSS pairs naturally with low-specificity selectors that compose cleanly.
2. Avoid IDs in Stylesheets
ID selectors are heavy and locked to single elements. Use classes for styling, reserve IDs for JS hooks and accessibility relationships (aria-labelledby).
3. Use :where() for Library Styles
Component libraries should wrap their CSS in :where(.lib) so application code can override with a single class. Modern CSS-in-JS libraries embrace this pattern.
4. !important Is a Last Resort
Use !important only for utility classes that MUST win (e.g. .visually-hidden). For everything else, raise the specificity slightly with an additional class — never via ID, never via !important.