CSS !important: when it wins and how to override it
CSS !important marks one declaration as important. An important author declaration beats a normal author declaration, but competing important declarations still follow the cascade. Origin, layers, and specificity can decide the result before source order matters.
Mark one declaration as important
Put !important after the value, before the semicolon. It applies to that declaration. In these two rules, the important dark-red declaration wins even though .demo .specificity is more specific.
.demo .specificity { color: #0369a1; }
.specificity { color: #9f1239 !important; }
W3C rules for important declarations
Run three cascade comparisons
Save the full file as important-demo.html in UTF-8 and open it in a browser. These comparisons use author styles.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Comparing !important declarations</title>
<style>
body {
margin: 2rem auto;
max-width: 38rem;
padding-inline: 1rem;
font: 1rem/1.6 system-ui, sans-serif;
background: #fff;
}
@layer vendor, app;
@layer vendor {
.layered { color: #9f1239 !important; }
}
@layer app {
.layered { color: #0369a1 !important; }
}
.demo .specificity { color: #0369a1; }
.specificity { color: #9f1239 !important; }
.tie { color: #9f1239 !important; }
.tie { color: #0369a1 !important; }
</style>
</head>
<body>
<main class="demo">
<h1>Comparing !important declarations</h1>
<p class="specificity" style="color: #166534">Competing with a normal inline style</p>
<p class="tie">Two important declarations with the same selector</p>
<p class="layered">Important declarations in different layers</p>
</main>
</body>
</html>
- The first line is dark red. Remove
!importantfrom.specificityto reveal the green inline color. Then remove the inline style to see the blue color from the more specific selector. Restore both changes. - The second line is blue. The two
.tiedeclarations have the same importance and selector, so the second wins. Temporarily disable it to see the dark red. - The third line is dark red. Both layer declarations are important, so the first layer in the order,
vendor, wins. Remove!importantonly from the vendor rule to see the blue inapp.
Compare competing important declarations
Specificity compares how narrowly selectors target elements. Once earlier cascade criteria such as origin and layer are tied, the more specific important declaration wins. Source order breaks a remaining tie. An inline important author declaration outranks important author stylesheet rules.
Cascade layers order groups of rules. Normal declarations favor later layers. Important declarations favor earlier layers and outrank important rules outside layers. Important user declarations outrank important author declarations, and an active transition can take precedence over an important declaration.
W3C cascade sorting order · W3C cascade layer order
Trace a style conflict in developer tools
- Inspect the element and find the affected property. Compare its computed value with the crossed-out declarations in the Styles panel to see what won.
- If you control the stylesheet, first scope the selector or rearrange the layers. When a third-party library uses normal declarations, importing its rules into an earlier layer can make overrides predictable.
- If you need an important declaration, scope it to the component and property and leave a short comment explaining why. Test relevant themes and interaction states.




