Lesson 48 of 50 · css
CSS for Performance – Avoiding Layout Thrash
Duration: 9 mins
Layout thrashing occurs when JavaScript reads layout properties (offsetWidth) then writes styles that cause a reflow.
- Prefer transform and opacity for animations (GPU‑accelerated).
- Batch DOM reads/writes using
requestAnimationFrame. - Use
containto limit reflow scope.
Example: Containment
.widget { contain:layout style; }