Performance: Transition utilities
Transition utilities affect the smoothness and speed of visual changes during user interactions, impacting the page's interaction responsiveness and visual stability.
Jump into concepts and practice - no test required
<button class="hover:bg-blue-500 transition-colors duration-500">Click me</button><button class="hover:bg-blue-500 transition-all duration-500">Click me</button>| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| transition-all on layout properties | Multiple style recalculations | Multiple reflows per frame | High paint cost | [X] Bad |
| transition-colors or transition-opacity | Minimal style recalculation | No reflows | Low paint cost, compositor only | [OK] Good |
transition utilities?transition-colors to animate color-related properties like background-color.duration-500 sets the animation duration to 500 milliseconds.<button class="bg-blue-500 hover:bg-blue-700 transition-colors duration-300">Click me</button>
transition-colors and duration-300, so color changes animate over 300 milliseconds.bg-blue-500 to bg-blue-700, which will animate smoothly.<div class="transition-opacity duration-200 hover:opacity-50">Fade me</div>
transition-opacity enables smooth opacity changes, which is correct here.hover:opacity-50 correctly sets opacity on hover, and duration-200 sets animation time to 200ms.scale) and shadow changes, so transition-all covers all properties.duration-500 with ease-in-out gives a smooth, balanced animation.hover:scale-105 grows size slightly, hover:shadow-lg adds a bigger shadow on hover.