
Not Important in CSS
In CSS, !important
is a special flag that can be added to a CSS rule to give it highest priority, overriding other conflicting rules — even those with higher specificity or coming later in the stylesheet.
Syntax:
selector { property: value !important;}
Example:
p { color: red !important;}p { color: blue;}
In this case, the paragraph (<p>
) text will be red, not blue, because the first rule has !important
.
Use Cases:
Overriding inline styles or third-party styles.
Quick fixes or testing.
Warnings:
Avoid overusing
!important
. It can make your CSS hard to maintain and debug.It breaks the natural cascade and specificity logic.
It's often better to refactor your CSS or increase specificity than to rely on
!important
.
Good Alternative:
Instead of:
.button { color: green !important;}
Prefer:
body .main-container .button { color: green;}
Use !important
only when absolutely necessary — like when dealing with styles you can't otherwise control (e.g., from browser extensions or third-party libraries).