!important: When and Why Not
Learn what !important does, why it's usually a design smell, and when it's actually appropriate.
!important: When and Why Not is a free CSS Academy lesson on CoddyKit. This is lesson 3 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the CSS Academy learning path, and your progress syncs across the web and the CoddyKit app. The CSS Academy course includes 4 lessons in total.
What !important Does
Adding !important after a declaration value gives it the highest priority in the author origin cascade, overriding all other author rules for that property regardless of specificity.
<p class="element" style="color: blue;">This text overrides the inline blue thanks to !important</p>The Legitimate Use Cases
There are valid reasons to use !important:
- User accessibility stylesheets — ensuring text remains readable
- Reduced motion override — disabling animations regardless of component styles
- Utility classes — ensuring a utility like
.hiddenalways wins - Third-party CSS override — when you cannot access the source
Utility Class Pattern
Utility classes that should always win are an appropriate use of !important — this is how Tailwind and Bootstrap utilities work:
<p class="hidden">This paragraph has class="hidden" and will not display (display: none !important).</p>
<p>This normal paragraph is visible so you can compare.</p>
<p class="sr-only">This text is screen-reader-only (visually clipped, still in the accessibility tree).</p>!important and the Cascade
!important declarations from the author origin have their own separate priority tier. Within that tier, specificity still applies — so two !important rules compete by specificity.
The Escalation Problem
When you use !important to fix a specificity problem, you create a new problem: anything needing to override that rule also needs !important, leading to escalating battles.
Debugging !important
In DevTools, an !important rule is shown with a yellow warning indicator. Crossed-out !important rules have been beaten by another !important with higher specificity — the rarest and most confusing CSS bug.
CSS @layer as Alternative
Use CSS layers instead of !important to give utility styles guaranteed priority over component styles without the !important escalation risk:
<div class="hidden">Hidden via the utilities layer (display: none) — layer order beats specificity without !important.</div>
<p>Visible content, unaffected by the layer utility above.</p>Removing !important from Legacy Code
Removing !important from a large codebase is risky. The safest approach: increase specificity of the overriding rule to match what !important was providing, then remove !important in a controlled diff.
!important in Animations
The reduced-motion override is a legitimate global use of !important:
<button class="btn">Animated button — durations become instant when prefers-reduced-motion: reduce is set on your device.</button>Code Review Rule
Treat every use of !important in a code review as a potential red flag requiring explanation. If the reason is "it would not work otherwise," that signals an underlying specificity architecture problem that should be fixed rather than papered over.
Summary: Use !important Sparingly
Use !important for utilities with guaranteed override semantics, accessibility overrides, and third-party CSS you cannot edit. Avoid it for fixing specificity conflicts — fix the specificity problem instead.
Quick Check
Two !important rules target the same property. Which wins?
Recap
!important overrides all author-origin specificity. Use it sparingly: utility classes, accessibility overrides, and third-party CSS patches are legitimate cases. Avoid using it to fix specificity bugs — use CSS @layer or lower specificity instead. Escalating !important usage is a sign of architectural problems.
Learn CSS with an AI tutor — free
Write and run real code in your browser, get instant help from a 24/7 AI tutor, and pick up where you left off on the web or in the app.
- Courses
- 40
- Lessons
- 159
Frequently Asked Questions
Is the “!important: When and Why Not” lesson free?
Yes — the full text of “!important: When and Why Not” is free to read here on the web. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the CSS Academy course, upgrade to CoddyKit PRO. The CSS Academy course includes 4 lessons in total.
What will I learn in “!important: When and Why Not”?
Learn what !important does, why it's usually a design smell, and when it's actually appropriate. You practise CSS Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start CSS Academy?
No prior experience is required. CSS Academy on CoddyKit is structured for beginners through advanced learners, so you can start here or from the beginning and move at your own pace. This is lesson 3 of 4.
How long does the “!important: When and Why Not” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this CSS Academy lesson?
Yes. Every CSS Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Specificity Calculation: Inline Style ID Class Element
- The Cascade: Origin and Order
- !important: When and Why Not
- Inheritance and the all Property