</> Code Corner

CSS · CSS Tutorial · Lesson 40

CSS !important

Override all previous styling rules.

The !important rule adds more importance to a property value than normal. It overrides all previous styling rules for that property on that element.

Example

<style>
#myid { background-color: blue; color: white; }
.myclass { background-color: gray; }
p { background-color: red !important; }
</style>
<p>This is some text in a paragraph.</p>
<p class="myclass">This is some text in a paragraph.</p>
<p id="myid">This is some text in a paragraph.</p>
Tip: The only way to override an !important rule is another !important rule with equal or higher specificity. Overusing it makes CSS hard to maintain.

Keep reading “CSS !important”

Sign up to read the full lesson, try every example in the live editor, and take the 5-question quiz.

Chat with us 👋