~/frontend-tools/css-specificity-calculator
CSS Specificity Calculator
Paste one or more selectors, one per line, and see the specificity of each as three numbers: IDs, classes and types. Selectors are ranked so you can see which rule wins, with correct handling of :is(), :not(), :has(), :where() and pseudo-elements.
Using the CSS Specificity Calculator
How specificity works
When two rules set the same property on the same element, the browser picks the one with the higher specificity. Specificity is compared as three numbers: first the count of ID selectors, then classes, attributes and pseudo-classes, then type selectors and pseudo-elements. A single ID beats any number of classes.
The special pseudo-classes
:is(), :not() and :has() take the specificity of their most specific argument. :where() always counts as zero, which makes it perfect for low-priority base styles that are easy to override. The universal selector * and combinators add nothing.
Ties and order
If specificity is equal, the rule that appears later in the stylesheet wins. Inline styles beat all selectors, and !important beats normal declarations; cascade layers (@layer) are compared before specificity.
Keeping specificity low
Long chains and IDs make CSS hard to override later, which leads to more !important and more frustration. Prefer single class selectors, use :where() for resets, and organise priorities with cascade layers.
Debugging a rule that will not apply
When a style refuses to apply, open the browser developer tools, inspect the element and look for your rule crossed out. Paste your selector and the winning selector into this calculator to see why one beats the other, then lower the winner's specificity or wrap base styles in :where() rather than reaching for !important.
How do I read the three numbers?
Specificity is written as three numbers, for example 0-2-1. The first counts IDs, the second counts classes, attributes and pseudo-classes, and the third counts element names and pseudo-elements. Compare them from the left: any selector with an ID beats any selector without one, no matter how many classes the other has.
Worked example: why a style does not apply
If #header .link (1-1-0) sets a colour and you write .nav .link.active (0-3-0), the ID rule still wins. Paste both selectors to see the scores side by side, then lower the first selector or raise the second rather than reaching for !important.
Frequently asked questions
Why does a selector with many classes lose to one with an ID?
Specificity is compared column by column, not added up. One ID in the first column outranks any number of classes in the second.
Do combinators like > and + count?
No, they add nothing to specificity.
Does it check my HTML?
No. It calculates specificity from the selectors alone.
Does !important change specificity?
No. !important puts a declaration in a separate, higher layer of the cascade. Among several !important declarations, specificity and order decide again, which is why overusing it leads to more of it.
Do inline styles have specificity?
Inline styles beat any selector in a stylesheet. They are often described as a fourth, higher column, which is why they are hard to override without !important.