When should I use !important, and why can it make CSS harder to change?
Quick answer
Use !important only when you have identified a genuine need to make a declaration important, such as when you cannot reasonably change the competing styles. It does not increase specificity: it changes how the cascade handles that declaration, and the full cascade still determines the winner. Before adding it, inspect the competing rules, their origins and layers, and selector specificity. Fix the underlying conflict where practical, so later changes remain easier to understand.
The question, the details, the next step.
A practical checklist
Inspect the element’s computed property and identify the winning rule.
Compare competing rules’ origins, cascade layers, selectors, and order.
Fix the rule that owns the unintended value when you can edit it.
Use
!importantonly for a justified constraint, not as a first override.Keep any necessary important declaration narrow and explain its purpose.
Verify the result on the target element and nearby elements.
A few more useful answers
Does `!important` make a selector more specific?
No. It marks the declaration important and changes its place in the cascade; it does not increase selector specificity. [S1]
Will a later `!important` rule always win?
No. The full cascade matters, including origin and layer order; specificity and source order settle ties at the relevant origin and layer. [S1]
Can I use `!important` to override styles from an external stylesheet?
It may be appropriate when you cannot reasonably change the competing stylesheet, but first identify the conflict. MDN suggests considering cascade layers for external styles and documenting intentional important declarations. [S1]
Sources
References used for this guide.
- [S1] !important CSS keyword — MDN developer.mozilla.org · Checked
- [S2] Handling conflicts — Learn web development — MDN developer.mozilla.org · Checked
