Overview
Tailwind CSS provides an! modifier (exclamation mark) that adds !important to utility declarations. This is useful when you need to override other styles with higher specificity.
Basic Usage
Add an! prefix to any utility to make it important:
The
!important flag increases the specificity of the declaration, making it override other conflicting styles regardless of selector specificity.With Variants
The important modifier can be combined with any variant:Multiple Variants
Common Use Cases
Overriding Third-Party Styles
When integrating third-party components with their own CSS:Utility-First Overrides
When you need to override a base style without changing it:Responsive Overrides
State-Based Overrides
Important Position
The! modifier can be placed at different positions:
Before the Utility (Standard)
After a Variant
Multiple Variants
With Arbitrary Values
The important modifier works with arbitrary values:With Custom Utilities
The important modifier works with custom utilities defined using@utility:
Compound Utilities
The important modifier applies to all properties in compound utilities:Limitations and Caveats
Doesn’t Work With These Patterns
The important modifier cannot be used in certain contexts:Specificity Doesn’t Change
Important changes the weight of the declaration, not the selector specificity:Alternative Solutions
Increase Specificity Instead
Often you can solve the problem by increasing specificity:Reorder Your HTML
Sometimes reordering classes is enough:Use More Specific Variants
Sometimes a more specific variant solves the issue:Custom Property Override
For components, consider using CSS custom properties:Best Practices
When It’s Acceptable
✅ Overriding third-party component styles ✅ Quick prototyping and testing ✅ Utility classes that should always win (rare) ✅ Bug fixes where refactoring is too riskyWhen To Avoid
❌ As a shortcut to avoid understanding specificity ❌ In reusable component libraries ❌ When you control all the CSS ❌ As the first solution you tryDebugging Important Utilities
When debugging important utilities in DevTools:Finding Important Conflicts
When multiple
!important declarations conflict, normal CSS cascade rules apply - the last declaration in source order wins.Performance Considerations
The important modifier has minimal performance impact:- Selector specificity calculations are the same
- No additional CSS is generated (just the
!importantflag) - Browser rendering performance is identical
Migration Guide
From Tailwind v3
The! modifier syntax is the same in v4:
From Inline Styles
Converting inline styles with important:Examples
Modal Overlay
Loading State Override
Print Styles
Source Code
The important modifier is handled in the candidate parsing and compilation system. The! character is detected and stripped from the candidate name, then !important is added to all declarations in the generated CSS.
Key files:
- Candidate parsing:
/packages/tailwindcss/src/candidate.ts - CSS generation:
/packages/tailwindcss/src/compile.ts