Performance: Hover variant
Hover variants affect interaction responsiveness and paint performance when users move their mouse over elements.
<button class="hover:bg-blue-500 hover:text-white">Click me</button> <button class="hover:bg-blue-500 hover:text-white">Click me</button> <button class="hover:bg-blue-500 hover:text-white">Click me</button> <!-- simpler hover styles -->
<button class="hover:bg-blue-500 hover:text-white hover:shadow-lg">Click me</button> <button class="hover:bg-blue-500 hover:text-white hover:shadow-lg">Click me</button> <button class="hover:bg-blue-500 hover:text-white hover:shadow-lg">Click me</button> <!-- repeated many times -->
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Complex hover styles (background, shadow) | None | Possible if layout changes | High paint cost | [X] Bad |
| Simple hover styles (opacity, transform) | None | None | Low paint cost | [OK] Good |
hover: prefix do in Tailwind CSS?hover: prefix in Tailwind applies styles only when the mouse pointer is over the element.hover: prefix followed by the utility class, e.g., hover:text-blue-500.hover:text-blue-500 matches the correct pattern. Others have incorrect order or invalid class names.<button class="bg-gray-300 hover:bg-green-400 text-black p-2 rounded">Click me</button>
bg-gray-300 for background normally and hover:bg-green-400 for background on hover.<div class="hover:bg-red-500 hovertext-white p-4">Alert</div>
hover:bg-red-500 is correct. The second class hovertext-white is missing a colon after hover.hover:text-white with a colon separating hover and the utility.bg-gray-400), hover background blue (hover:bg-blue-600).text-gray-800), hover text is white (hover:text-white).bg-gray-400 hover:bg-blue-600 text-gray-800 hover:text-white p-3 rounded matches all requirements with correct syntax. Others have wrong class names or order.Pass the test and this pattern moves unknown