!important RuleThe CSS !important rule is used to give a specific property the highest priority in the cascade. When multiple CSS rules target the same element and property, the one marked with !important will win—even over inline styles or more specific selectors. Because it is so powerful, it should be used carefully, only when you really need to force a style.
!important beats normal rules, even if they are more specific.!important can override inline styles without !important.!important, the one with higher specificity wins.!important can make your CSS confusing and difficult to maintain.!important.!important: Very high priority!important: Highest priority (if specificity is equal)The !important keyword is written at the end of a property value, just before the semicolon. It works with any CSS property and tells the browser, “apply this value even if other rules try to override it.”
/* Basic syntax for the !important rule */
selector {
property: value !important;
}
Under the hood, the browser still uses the normal cascade and specificity rules, but !important acts like an extra boost. When multiple !important rules apply to the same property, specificity and source order are used to break the tie.
In this example, both rules target the same paragraph. The second rule uses !important, so it wins even though the first rule appears later in the stylesheet.
/* First rule: sets paragraph text to blue */
p {
color: blue;
}
/* Second rule: !important makes the text red instead */
p {
color: red !important;
}
Even though the first rule sets the text to blue, the paragraph will appear red in the browser because the second rule uses !important.
Normally, inline styles have higher priority than external or internal stylesheets. But a stylesheet rule with !important can even override inline styles that do not use !important.
/* Stylesheet rule with !important */
p {
color: red !important;
}
<!-- HTML with inline style trying to set blue color -->
<p style="color: blue;">This paragraph will look red when the CSS above is applied.</p>
In this standalone page, this text is blue because only the inline style is active. In a real project, if you also add the red !important rule from the code example, the paragraph would be rendered in red despite the inline style="color: blue;".
!important Rules ClashIf two rules for the same element and property both use !important, then specificity and order in the stylesheet decide the winner.
/* Class selector with !important */
.title {
color: green !important;
}
/* ID selector with !important (higher specificity) */
#mainTitle {
color: orange !important;
}
<!-- HTML element using both the ID and class -->
<h1 id="mainTitle" class="title">CSS !important Example</h1>
Both rules use !important, but the ID selector #mainTitle is more specific than the class selector .title. So the heading text will be orange.
!important!important only when you cannot change the original CSS (e.g., third-party libraries or legacy code).!important.!important rules documented or grouped so others know why they exist.!important rule, use another !important rule with higher specificity or place it later in the stylesheet.!important in global selectors like body or *, as that can break theming and reuse.!important. Change colors and see which one applies.!important to override the inline style.!important rule.!important rules (one using a class, one using an ID) and observe how specificity decides the winner.