Performance: Transform (scale, rotate, translate)
This affects how the browser paints and composites elements, impacting animation smoothness and interaction responsiveness.
Jump into concepts and practice - no test required
<div class="w-32 h-32 bg-blue-500 transform transition-transform duration-300" style="transform: translateX(100px) scale(1.5);"></div>
<div class="w-32 h-32 bg-blue-500" style="width: 200px; left: 100px; position: relative; transition: width 0.3s, left 0.3s;"></div>
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Animating width and position | Multiple style changes | Multiple reflows | High paint cost | [X] Bad |
| Animating with transform (scale, rotate, translate) | No DOM changes | No reflows | Low paint cost (composite only) | [OK] Good |
scale-110 do to an element?scale-110 class in Tailwind increases the size of the element by 110%, which means 10% larger than normal.rotate- and translate-. Transparency uses opacity classes, not scale.rotate- followed by degrees to rotate elements. rotate-45 means rotate 45 degrees clockwise.scale- changes size, translate- moves position, and rotate-90 rotates 90 degrees, not 45.<div class="transform translate-x-4 rotate-90 scale-50 bg-blue-500 w-20 h-20">Box</div>
translate-x-4 moves the element right by 1rem (4 * 0.25rem), rotate-90 rotates it 90 degrees clockwise, and scale-50 scales it to 50% size (half).<div class="transform scale-150 rotate-360 translate-y-6px">Content</div>
translate-y-6, not custom units like 6px. So translate-y-6px is invalid.rotate-360 is valid (full rotation), and scale-150 is valid (150% size). The transform class is present.hover:scale-125 and hover:rotate-15. The base transform class enables transforms.transition duration-300 for smooth animation over 300ms. Other options either miss hover prefixes or use wrong values.