CSS Specificity Calculator
Compute the specificity of a CSS selector and compare two selectors.
- Runs locally in your browser
- No upload required
Try it
Supported formats
Privacy
Runs entirely in your browser. Your input is never uploaded, stored, or sent to a third party.
Specificity is (a=1, b=2, c=1). Higher a wins first, then b, then c regardless of source order.
How it works
- Count id selectors as a.
- Count classes, attributes and pseudo-classes as b.
- Count type selectors and pseudo-elements as c; `:where()` adds nothing and `*` adds nothing.
- For `:not()`, `:is()` and `:has()`, use the most specific argument.
specificity = (ids, classes/attributes/pseudo-classes, types/pseudo-elements)- Inline styles and `!important` are handled separately by the cascade and are not part of this triple.
- This is a pragmatic tokeniser: it follows the CSS Cascade rules for the common selector grammar.
Methodology
- Split the input on top-level commas into a selector list.
- Walk each selector and count id selectors (a), class/attribute/pseudo-class selectors (b) and type/pseudo-element selectors (c).
- Treat `:where()` as zero and `:not()`/`:is()`/`:has()` as the most specific argument.
- Report the highest triple for the list and label the most and least specific selectors.
Usage
- Enter one CSS selector, or a comma-separated selector list.
- Read the (a, b, c) specificity triple and the per-component breakdown.
- For a list, compare the most and least specific selectors.
Examples
These are examples, not current values: they use fixed inputs, while the interactive tool computes live results in your browser.
Id, class, type and pseudo-class
{
"selector": "#app .card a:hover"
}Attribute and pseudo-element
{
"selector": "input[type='text']::placeholder"
}Selector list
{
"selector": "ul li, .nav a, #main"
}Limitations
About the specificity triple
The triple (a, b, c) is compared left to right: a higher `a` always wins, then a higher `b`, then `c`. This is why a single id selector beats any number of classes, and why the number is written `1,1,3` rather than a single integer.
The calculator is a reading aid for debugging the cascade. It does not evaluate `@layer`, `@scope`, inline styles or `!important`, so use it alongside the browser devtools for the full picture.
Frequently asked questions
- Which value wins when two selectors have the same specificity?
- The one declared later in the source order wins, all else being equal.
- How much does :where() add?
- Nothing. `:where()` always contributes zero specificity, which is what makes it useful for low-priority defaults.
Sources
Send feedback
Tell us if this tool helped, report a problem, or suggest a tool. Only the message you type is sent — never the input you used in the tool.
Was this tool useful?
Prefer to write to us directly? See the contact page.