The CSS Cascade
When multiple rules target the same element, the cascade determines which one wins. It considers importance, specificity, and source order.
Later rules override earlier ones when specificity is equal.
When multiple rules target the same element, the cascade determines which one wins. It considers importance, specificity, and source order.
Later rules override earlier ones when specificity is equal.
/* Source order: last one wins if specificity is equal */
p { color: blue; }
p { color: red; } /* This wins */
/* !important overrides everything (avoid when possible) */
p { color: green !important; }
Understand the cascade before reaching for !important — most specificity problems can be solved with better selectors.