Sometimes, different CSS classes try to change the same style in different ways. Class conflict resolution helps decide which style wins so your page looks right.
Class conflict resolution strategies in Tailwind
<!-- Tailwind classes in HTML element -->
<div class="class1 class2 class3">Content</div>hover: or md: applies styles only in certain states or screen sizes, helping avoid conflicts.text-blue-500 comes after text-red-500 and overrides it.<div class="text-red-500 text-blue-500">Hello</div>p-4.<div class="p-4 p-2">Box</div>hover: prefix.<button class="bg-green-500 hover:bg-green-700">Click me</button>md: prefix to resolve conflicts by screen size.<div class="text-sm md:text-lg">Text</div>This example shows how Tailwind resolves conflicts by applying the last class for the same property. The heading text is blue because text-blue-700 overrides text-red-500. The paragraph has smaller padding because p-2 overrides p-6. The button changes background color on hover using the hover: prefix.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1" /> <title>Tailwind Class Conflict Example</title> <script src="https://cdn.tailwindcss.com"></script> </head> <body class="p-6"> <h1 class="text-red-500 text-blue-700 font-bold">Hello World</h1> <p class="p-6 p-2 bg-gray-100">This paragraph has padding conflict.</p> <button class="bg-blue-500 hover:bg-blue-700 text-white font-semibold py-2 px-4 rounded"> Hover me </button> </body> </html>
Order matters: Tailwind applies classes from left to right, so put the class you want to win last.
Use prefixes like hover:, focus:, or responsive prefixes like sm:, md: to avoid conflicts by targeting states or screen sizes.
Inspect elements in browser DevTools to see which styles are applied and which are overridden.
Tailwind resolves class conflicts by applying the last class that affects the same CSS property.
Use state and responsive prefixes to manage styles in different situations without conflicts.
Check your class order and use browser tools to debug style conflicts.