#1 Data Analytics Program in India
₹2,499₹1,499Enroll Now
2 min read
Question 24 of 38medium

How to use !important in Tailwind?

Forcing specificity with important modifier.

What You'll Learn

  • Important modifier
  • When to use it
  • Configuration options

Important Modifier

index.htmlHTML
<div class="!p-4">Forces p-4 with !important</div>
<div class="!bg-red-500">Forces background color</div>

Use Cases

index.htmlHTML
<!-- Override third-party styles -->
<div class="third-party-class !text-blue-500">
  Overrides library styles
</div>

<!-- Override inline styles (in some cases) -->
<div style="color: red" class="!text-blue-500">
  May override inline
</div>

Global Important Mode

code.jsJavaScript
// tailwind.config.js
module.exports = {
  important: true,  // All utilities get !important
}

// Or with selector
module.exports = {
  important: '#app',  // Increases specificity
}

Best Practices

  • Use sparingly
  • Prefer proper specificity management
  • Consider component architecture
  • Document when used