CSS: !important
What is the !important keyword
The !important keyword marks a style rule to override all other conflicting rules.
Syntax
the !important keyword must be at the end of a rule, immediately before the semicolon.
p { color: red !important; }
The priority of !important
Rules with important flag take priority over any other rules.
but when 2 rules are both declared important, the priority is this, from lowest priority to high:
!importantin website style sheet. (lowest priority)!importantin user style sheet!importantbrowser style sheet
note the reverse of order of origin, when compared to normal cascade.
Within the same origin + importance level, the rest of the cascade still applies:
- Cascade layers (order is also reversed for !important)
- Specificity
- Source order (later wins)
Tip: do not use important
🟢 TIP: do not use the !important, because it makes your CSS hard to maintain once you have more than one.