CSSMedium
How is CSS specificity calculated?
By FrontendPro Editorial Team Updated 8/7/2026
#css#specificity#cascade
Answer
Score as a tuple of (inline, id, class/attribute/pseudo-class, element/pseudo-element), compared left to right:
| Selector | Score |
|---|---|
div p | 0,0,2 |
.card p | 0,1,1 |
#main p | 1,0,1 |
style="…" | inline, beats all |
Key points:
- On a tie, the later declaration wins.
!importantjumps above the normal cascade (except user-stylesheet!important).:is()/:not()take the specificity of their strongest argument;:where()is always 0 → perfect for easily-overridable defaults.@layerorders precedence without a specificity arms race.
