CHAPTER 42
CSS !important
Learn what !important does, why it overrides normal declarations and when it should be avoided.
01. What is CSS !important?
!important gives a CSS declaration very high priority within the cascade.
It can override normal declarations that would otherwise win.
It should be used carefully because excessive use makes CSS difficult to maintain.
02. Syntax
selector {
property: value !important;
}
03. Example
CSS / HTML Example
AIFA Coding Lab
<!DOCTYPE html>
<html>
<head>
<style>
p {
color: blue;
}
.special {
color: red !important;
}
</style>
</head>
<body>
<p class="special">
This text will be red.
</p>
</body>
</html>
04. Important Points
✓
!important changes the priority of a declaration.
✓
Use it only when there is a genuine need.
✓
Understanding the cascade and specificity is usually better than repeatedly using !important.
✓
Avoid building an entire stylesheet around !important.
05. Common Mistakes
⚠
Using !important on every rule.
⚠
Using !important instead of fixing selector specificity.
⚠
Making reusable CSS components difficult to override.
06. Real World Use
!important can occasionally be useful when overriding third-party styles or special utility classes, but normal CSS organization should be preferred.
Ready to Practice? 🚀
Open the AIFA CSS Editor and practice this chapter live.
Try It Yourself →
Practice Exercise
Understand !important
Create two conflicting color rules and use !important on one declaration. Observe the result.