-
Hajipur, Bihar, 844101
!important
?The !important
declaration in CSS is used to force a style rule to be applied, even if other rules have higher specificity.
When you add !important
to a property, that rule will override all other rules for that property, regardless of where it appears or its specificity.
selector {
property: value !important;
}
p {
color: red !important;
}
#main p {
color: blue;
}
The paragraph will appear red because
!important
overrides the more specific selector.
!important
✅ Use when:
You must override third-party CSS (e.g., Bootstrap)
Inline or high-specificity styles need to be overridden
Quick fixes are required temporarily
❌ Avoid when:
Writing scalable, maintainable CSS
You can use better selector specificity instead
!important
<p style="color: blue;">This is a paragraph</p>
p {
color: red !important;
}
Result: Red, because
!important
even overrides inline styles.
!important
RulesIf two !important
rules apply, the one with higher specificity wins.
p {
color: green !important;
}
#intro p {
color: purple !important;
}
Final color: purple (because
#intro p
is more specific)
Q1. Apply a red background to all paragraphs using !important
.
Q2. Force font-size 18px on all buttons regardless of previous styles.
Q3. Override Bootstrap’s btn-primary
color using !important
.
Q4. Make all <h1>
text uppercase using !important
.
Q5. Use !important
to set a 2px solid border on input fields.
Q6. Style all <a>
links with orange color and override any hover effects.
Q7. Add padding to divs and make sure it applies despite inline styles.
Q8. Make text color black for .error
class and override all other rules.
Q9. Style disabled buttons with grey background using !important
.
Q10. Change list item marker style to square using !important
.
Q1: What does !important do in CSS?
Q2: Which rule takes precedence if both use !important?
Q3: How to override an inline style using CSS?
Q4: Which of these declarations is correct?
Q5: Should you overuse !important in large projects?
Q6: What happens if two rules with !important conflict?
Q7: Which is more powerful?
Q8: Where can !important be used?
Q9: What is the main drawback of using !important everywhere?
Q10: What’s the correct order of priority (lowest to highest)?