CSS Specificity & the Cascade
When multiple CSS rules target the same element, the browser must decide which one wins. This is governed by specificity and the cascade.
Specificity Score (highest wins)
!important— Overrides everything (use sparingly)- Inline styles (
style="...") - ID selectors (
#id) - Class / pseudo-class / attribute selectors (
.class,:hover) - Element selectors (
p,div)
The Cascade Rules
When specificity is equal, the last rule in the stylesheet wins (order matters).
💡 Avoid !important in most cases — it makes debugging very hard.