Skip to content

CSS !important Not Working

Quick summary

Your !important rule is not winning because another rule with !important has higher specificity, or the rule is not matching.

Why this happens

  • Another !important rule with higher specificity is overriding it

  • The CSS selector is not matching the target element

  • Inline styles with !important override stylesheet rules

Minimal example

✗ Broken code
/* Specificity: 0-1-0 */
.btn { color: red !important; }
/* Specificity: 1-0-0 — wins even with !important on both */
#special-btn { color: blue !important; }
✓ Fixed code
/* Increase specificity to match or exceed */
#special-btn.btn { color: red !important; }

When both rules have !important, specificity decides. #special-btn (1-0-0) beats .btn (0-1-0). Increase your selector's specificity to win.

How to diagnose

  • Inspect the element in DevTools — look for struck-through !important rules

  • Check if another !important rule with higher specificity exists

  • Verify the selector matches the element

How to fix

  • Increase the specificity of your !important rule

  • Remove the competing !important declaration

  • Use inline style with !important as a last resort

How to prevent

  • Avoid !important — use specificity and source order instead

  • Use a structured CSS architecture (BEM, CSS modules) to avoid conflicts

Related Resources

Related Glossary

Related Lessons

← Back to language