You added !important. The style still lost. Now you are in DevTools wondering how that is even possible.
Here is what almost no one spells out: !important does not override other styles. It raises a declaration's priority inside the cascade, and specificity, origin, cascade layers and source order still pick the winner. Misread that one fact and !important feels random. Get it right and every conflict has an explanation. This guide gives you the explanation, then the fixes that do not involve stacking another flag.
!important flag marks a declaration as important, which moves it into a higher importance band in the cascade. It does not switch off specificity. Inside that band, origin, cascade layer, specificity and source order resolve the winner exactly as they always do.!important changes which importance band a rule competes in. It does not win by brute force.!important breeds specificity wars and unpredictable rendering.@layer cascade layers resolve conflicts without a single flag.What !important actually does, and the misconception
If you write CSS daily, typing !important is not the hard part. What trips people up is what it changes. The flag marks a declaration as important, which moves it into a higher importance band in the cascade. It does not win by brute force, and it does not switch off specificity.
That distinction explains the behavior that confuses developers. Take two important rules on the same element:
css.button { background: blue !important; }
#header .button { background: red !important; }
The button renders red, and the second rule wins. Not because it appears later, but because both declarations are important author declarations, so the cascade falls through to the next tie-breaker, specificity, where #header .button outweighs .button. The flag did not end the contest. It raised both rules into the same band, and the normal rules resolved it.
Hold onto that model: !important decides which importance band a declaration competes in, and then origin, cascade layer, specificity and source order run exactly as they always do. Almost every surprising !important result is one of those lower tie-breakers deciding the winner after the flag put the rules on equal footing.
How !important changes the CSS cascade
The cascade is the process the browser uses to pick a winning declaration when several rules target the same property on the same element. It sorts candidates by importance and origin first, then by cascade layer, then by specificity, then by source order. The flag acts on the importance step, not the specificity step.
From highest priority to lowest, the cascade sorts declarations in this order:
- Transition declarations
- Important user agent declarations
- Important user declarations
- Important author declarations
- Normal author declarations
- Normal user declarations
- Normal user agent declarations
Two rows in that list explain bugs you have probably hit. First, important user declarations outrank important author declarations. This is deliberate: it protects a reader's own stylesheet, such as a high-contrast or large-font override, from being erased by the site author. Second, a running transition can take precedence even over an important declaration while it animates, so a property mid-transition may not show the value you expect to win.
Cascade layers add another step between origin and specificity. Within the same importance band, a declaration in a later-ordered layer beats one in an earlier layer, which is the lever that lets you order groups of styles without reaching for !important at all.
Why overusing !important breaks things
A single flag rarely breaks a site. The trouble comes from frequent use, because each flag pulls a property out of the normal cascade and makes the rendered result harder to predict. Five patterns account for most of the pain.
01Specificity wars
Once one rule uses !important, the only way to beat it is another important declaration with equal or greater specificity. Teams escalate, stacking !important on top of !important, until the stylesheet is a pile of overrides nobody can safely remove.
02Difficult debugging
When an important declaration wins, the value you see may come from a rule in a file you were not even looking at. Tracing which declaration took effect, and why, costs more than resolving a normal specificity conflict where selector weight and source order explain the outcome.
03Unexpected component behavior
A shared component styled with !important cannot adapt to the context it drops into. A button that forces its background important looks identical inside a warning banner, a dark footer and a compact toolbar, even when each context needs a different treatment.
04Accessibility impact
When authors use !important pervasively, readers who rely on their own stylesheets are pushed to use it too, just to restore a larger font, a different font family or a changed layout. The cascade still lets a user important rule win over an author important rule, so the override is not blocked outright, but the page becomes hostile to the customization disabled users depend on.
05Harder stylesheet maintenance
Every added flag increases code complexity and makes rendering less predictable. Over months the stylesheet collects rules that exist only to defeat earlier important rules, and refactoring grows risky because any change can expose a style that was being suppressed.
How to fix CSS conflicts without !important
Most conflicts that tempt you toward the flag can be resolved by working with the cascade instead of against it. Reach for these in roughly this order.
01Check selector specificity first
If a rule is not applying, compare the specificity of the competing selectors before anything else. Adding a parent tag, id or extra class to the losing selector often settles it cleanly:
css/* Loses */
.button { background: blue; }
/* Wins on specificity, no !important needed */
#main-container .button { background: red; }
Raising specificity is not always the right fix, though. Push it too far and you recreate the specificity war you were trying to avoid, so prefer the smallest increase that wins.
02Review stylesheet source order
When two selectors have equal specificity, the one that appears later in the source wins. Sometimes the cleanest fix is to move a rule later in the file, or load one stylesheet after another, rather than touching the selectors at all.
03Refactor and scope conflicting styles
If the same property is set in several places, consolidate those rules into one source of truth instead of layering overrides on top. Scoping styles to a component, through CSS Modules, Shadow DOM or a build-time scoping convention, stops global rules from colliding with component rules in the first place, which removes the pressure to escalate.
Cascade layers in practice
The @layer rule lets you declare an explicit precedence order for groups of styles. A declaration in a later layer beats one in an earlier layer for normal declarations, with no change to specificity:
css@layer base, components, overrides;
@layer base {
.button { background: blue; }
}
@layer components {
.button { background: red; }
}
Here the components layer wins over base regardless of selector weight. Cascade layers are especially useful for managing third-party CSS: drop an external stylesheet into an early layer, keep your own rules in a later one, and your styles win without a single flag. This table shows which tool to reach for first.
| Situation | Reach for | Avoid |
|---|---|---|
| A rule loses to another of lower specificity | Specificity | Raising it past what wins |
| Equal specificity, wrong rule wins | Source order | An !important flag |
| Third-party CSS overrides your styles | @layer | Chained !important |
| Same property set in many files | Refactor | Another override on top |
| Global rules leak into a component | Scoped styles | Important on the component |
| Beating an inline style attribute | !important | Editing the markup if you cannot |
When using !important is acceptable
The flag has a few legitimate uses, though cascade layers now cover several of them more cleanly. Reasonable cases include:
- Utility classes that must not be overridden. A helper such as
.hidden { display: none !important; }is sometimes made deliberately immutable so no component rule can accidentally reveal it. - Overriding inline styles or third-party code. Inline styles beat normal author rules on specificity, and some widgets ship styles you cannot edit. An important declaration takes back control, though a cascade layer or more specific selector is often enough.
- Print stylesheets. Forcing colors, backgrounds or visibility for print output is a context where important rules are common and low-risk.
- Email styling. Email clients strip and reorder CSS unpredictably, so important declarations are a practical defense there.
- End-user and accessibility stylesheets. A reader's own stylesheet can use
!importantto enforce a larger font or higher contrast, and the cascade guarantees those user important rules win over author important rules.
Even in these cases, use the flag deliberately. Overusing it limits a reader's ability to adapt the experience and raises long-term maintenance cost, so treat each use as a decision you could justify, not a reflex.
How to find and debug CSS styling conflicts
Before adding any override, find out which declaration is actually winning and why. Browser DevTools is the fastest path.
- Inspect the element. Open DevTools, select the element and read the Styles panel. Losing declarations are shown struck through, so you can see at a glance which rule took effect.
- Read the cascade top to bottom. The winning declaration sits at the top of the matched rules. Note its selector and source file, which tells you where the value really comes from.
- Check for important and inline styles. An important declaration or an inline
styleattribute outranks ordinary rules. Spotting one explains a conflict that specificity alone does not. - Fix the cause, not the symptom. Once you know which rule wins, resolve it with specificity, source order or a cascade layer rather than stacking another flag.
Using !important briefly during development can be a useful diagnostic: force a property, confirm you are editing the element you think you are, then remove the flag and solve the conflict in the cascade.
CSS conflicts are not always visible across an entire site. A change to a shared stylesheet can affect many templates, components and page layouts at once, and a fix that looks correct on one page can shift something on another. After modifying shared CSS, inspect the affected pages and compare them against the previous version to catch unintended changes.
!important raises priority. It does not end the cascade.
Why not just hack specificity or inline everything
Two shortcuts look faster and cost you later. Inflating specificity with throwaway ids or duplicated classes wins the moment but leaves a selector no future rule can beat without copying the hack, which is the specificity war in slow motion. Inline styles win by sitting high in the cascade, yet they cannot be reused, themed or overridden except with the very flag you are trying to avoid. Cascade layers and scoped styles solve the same conflicts while keeping your CSS readable and overridable, so the next change stays a one-line edit instead of an archaeology project.
CSS !important best practices
- Treat
!importantas a last resort, not a default way to make a style stick. - Remember it raises cascade priority, it does not switch off specificity, origin, layers or source order.
- Resolve conflicts with specificity, source order and cascade layers before reaching for the flag.
- Prefer
@layerover!importantwhen integrating third-party or utility CSS. - Avoid specificity escalation: the smallest selector change that wins beats a heavier one.
- Document any intentional
!importantuse so a later reader knows it was a decision. - Never block user and accessibility overrides with pervasive important rules.
- After editing shared CSS, re-check affected pages and compare against the previous version before shipping.
Frequently asked questions
Does !important override everything in CSS?
No. It raises a declaration into a higher importance band, but inside that band origin, cascade layer, specificity and source order still decide the winner. A more specific important rule beats a less specific one.
Why is my !important rule not working?
Usually another declaration is also important and wins on a later tie-breaker: greater specificity, a later cascade layer, later source order, or a user or user agent important rule. Inspect the element in DevTools to see which rule took effect.
Is it bad to use !important in CSS?
A single, deliberate use is fine. The problem is frequent use, which causes specificity wars, harder debugging and unpredictable rendering. Prefer specificity, source order and cascade layers first.
How do I override an !important rule without using !important?
Place your styles in a later cascade layer with @layer, or, if both rules are important, increase the specificity of your selector so it wins within the important band. Refactoring the conflicting rule is cleaner still.
What is the difference between !important and specificity?
Specificity measures how targeted a selector is and is one tie-breaker in the cascade. !important is a separate, higher step that moves a declaration into the important band. Specificity is only compared after importance and origin.
Sources: MDN Web Docs on !important, the cascade and cascade layers, and the CSS Cascading and Inheritance Level 5 specification. Code examples authored for this post.
Related reading
Cascade. Specificity. Layers. Ship.
A flag that forces a style is not a fix. It just hides which rule should have won.
Catch CSS regressions and technical issues across your whole site before they reach your users.
Fix the cascade