Overview
The cascade resolves conflicts when several declarations target the same property on the same element. When a style refuses to apply, debug the cascade before adding !important: the winner is usually a different layer, higher specificity, or later source position.
Rules
The first step that differs decides the winner:
- Origin and importance. Author
!importantbeats normal author styles; user-agent and user!importantbeat author!important. Animations and transitions rank above normal declarations. - Inline
styleattributes beat selector rules of the same origin and importance. - Cascade layers (
@layer). For normal declarations, later layers win and unlayered styles beat all layers. For!importantthe order reverses: earlier layers win and unlayered loses. - specificity.
@scopeproximity, then source order (the last declaration wins).
Properties no rule sets inherit from the parent (text properties such as color) or take the initial value (layout properties such as width). Put third-party CSS in an early layer so your unlayered styles win without !important.
@layer base, components;
@layer components { .card p { color: teal; } }
p { color: black; } /* unlayered: wins despite lower specificity */Related
- specificity: step 4 of the cascade.
- custom-property: custom properties inherit and cascade like others.
- css-cascade-layers: layer strategy in depth.
- css: CSS rules and conventions.
- css-selectors: selector weights.