CSS Specificity Calculator
Calculate CSS selector specificity and understand why a rule loses to another that looks less specific.
Last reviewed by the Radiatus Cloud team
Need this built for your product?
We design, build & host secure software & APIs.
How specificity is counted
A selector's specificity is three numbers: inline styles, then IDs, then classes, attributes and pseudo-classes, then elements and pseudo-elements. They are compared left to right, and a higher number in an earlier position wins regardless of the later ones. This is the crucial part: specificity is not a sum. A single ID beats any number of classes, because the comparison never reaches the class column.
Source order only breaks ties
When two selectors have identical specificity, the one declared later wins. That is why moving a rule to the bottom of a stylesheet sometimes fixes things and sometimes does nothing at all: it only helps when specificity is already equal.
The universal selector and combinators count for nothing
The asterisk, and the combinators for child, sibling and descendant, add zero specificity. A long descendant chain is not automatically more specific than a short one; only the compound selectors within it count.
Where and is are the useful modern tools
The where pseudo-class always contributes zero specificity, which makes it ideal for default styles that should be trivially overridable. The is pseudo-class takes the specificity of its most specific argument, so the two are not interchangeable. Using where for base layers is the cleanest way to avoid specificity escalation in a design system.
Important is not a specificity level
It sits outside the calculation entirely, overriding any specificity in the same origin. Its only real counter is another important declaration with higher specificity, which is how stylesheets end up with important on nearly everything. Treat any need for it as a signal that the selector strategy has failed, with the honest exception of overriding third-party CSS you do not control.
Cascade layers change the picture
Layers now take precedence over specificity: a rule in a later layer beats a more specific rule in an earlier one. That inverts the usual mental model and is the modern answer to specificity wars, letting a low-specificity rule in your overrides layer beat a framework's high-specificity selector without any important at all.
Related tools
- JSON Formatter — Format and beautify JSON in your browser. Pinpoints syntax errors by line and column, flags unsafe integers, and never uploads your data to a server.
- JSON Validator — Validate JSON syntax with precise line and column errors, and check documents against a JSON Schema. Runs locally in your browser, nothing uploaded.
- Regex Tester — Test regular expressions against sample text with live match highlighting, capture groups and flag control. Runs entirely in your browser.
- HTML Minifier — Minify HTML by removing comments and redundant whitespace, without breaking inline elements or pre blocks. Runs entirely in your browser.
Frequently Asked Questions
Why does my class rule lose to an ID?
Because specificity is compared column by column, not summed. A single ID beats any number of classes, since the comparison never reaches the class column once the ID column differs.
Does moving a rule later in the file help?
Only when specificity is already equal. Source order breaks ties and nothing else, which is why the trick sometimes works and sometimes has no effect at all.
What is the difference between :where and :is?
The where pseudo-class always contributes zero specificity; is takes the specificity of its most specific argument. Use where for base styles that should be trivially overridable.
Is !important a specificity level?
No, it sits outside the calculation and overrides any specificity in the same origin. Needing it usually signals a failed selector strategy, with the honest exception of overriding third-party CSS.
How do cascade layers affect specificity?
They take precedence over it. A rule in a later layer beats a more specific rule in an earlier one, which lets a simple override beat a framework's complex selector without using important.
Privacy & Security
All processing happens locally in your browser — nothing is uploaded.
How to Use
Paste a CSS selector to see its specificity breakdown and total score.
Disclaimer: This tool is provided "as is" without warranty of any kind. Results are for educational and utility purposes.
Related Tools
JSON Formatter
DeveloperFormat and beautify JSON in your browser. Pinpoints syntax errors by line and column, flags unsafe integers, and never uploads your data to a server.
JSON Validator
DeveloperValidate JSON syntax with precise line and column errors, and check documents against a JSON Schema. Runs locally in your browser, nothing uploaded.
Regex Tester
DeveloperTest regular expressions against sample text with live match highlighting, capture groups and flag control. Runs entirely in your browser.