Adding !important to a declaration lifts it above normal declarations, whatever their specificity.
<style>
#intro { color: red; }
.note { color: blue !important; }
</style>
<p id="intro" class="note">I am blue, even though an ID selector wants me red.</p>
The ID rule is much more specific, but !important beats it.
Why it is a trap
Once you use it, the only way to override it is another !important with equal or higher specificity, or later in the file. A stylesheet full of !important becomes a shouting match where nothing can be changed without making it louder.
/* Today */
.button { background: blue !important; }
/* Next month, a variant needs a different color */
.button-danger { background: red !important; } /* and now order decides */
Better alternatives
- Look at the real cause. Find the rule that is winning in the developer tools, and lower its specificity or change it.
- Make your selector slightly more specific:
.card .titleinstead of.title. - Reorder. Place the rule after the one you want to beat.
- Use a class instead of an ID in the stronger rule so it is easy to beat.
- Use CSS layers (
@layer) to control the order of whole groups of rules. It is an advanced tool, but it solves specificity battles at the root.
When it is acceptable
- Utility classes meant to always win:
.hidden { display: none !important; }. - User preferences such as the reduced motion override.
- Overriding third-party CSS or inline styles you cannot edit.
- Print styles that must override everything.
In your own component styles, avoid it.
Debugging a stuck style
!important on the rule that is winning, you need another !important or a better fix. Searching your files for !important is one of the quickest ways to find the problem.