Performance: Active variant
This affects the browser's rendering performance during user interactions, especially when the active state triggers style changes.
<button class="bg-blue-500 active:bg-blue-700 transition-colors duration-150">Click me</button><button class="bg-blue-500 active:bg-blue-700 active:shadow-lg active:text-xl transition-all duration-150">Click me</button>| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Active variant with color change only | Minimal | 0 | Low | [OK] Good |
| Active variant with font-size and shadow | Minimal | 1+ per toggle | High | [X] Bad |
active: variant in Tailwind CSS do?active: variant purposeactive: variant targets the moment an element is clicked or pressed, giving immediate feedback.active:.active: = clicked/pressed state [OK]bg-red-500, and the active state changes it to bg-red-700.<button class='bg-red-500 active:bg-red-700'>Click me</button> correctly sets the base and active variant. Other options either reverse colors or misuse classes.<button class='bg-red-500 active:bg-red-700'>Click me</button> [OK]<button class='bg-blue-400 active:bg-blue-600 text-white px-4 py-2 rounded'>Press</button>
bg-blue-400. The active variant changes it to bg-blue-600 when pressed.active:bg-blue-600 applies, overriding the base color.<button class='bg-green-500 active-bg-green-700 text-white'>Click</button>
active:bg-green-700. The code uses a dash instead, which is invalid.active:bg-green-700 -> Option Dtext-gray-800 and change to text-purple-600 only when pressed, so active:text-purple-600 is correct.transition-colors and duration-300 for smooth color transitions on press and release.<a href='#' class='text-gray-800 active:text-purple-600 transition-colors duration-300'>Link</a> [OK]Pass the test and this pattern moves unknown