CSSHard
Why should you animate only transform and opacity?
By FrontendPro Editorial Team Updated 8/14/2026
#css#performance#animation
Answer
The render pipeline is style → layout → paint → composite.
- Animating
width,top,marginre-runs layout every frame → jank. - Animating
background-color,box-shadowre-runs paint. - Animating
transform/opacityonly composites, on the GPU, off the main thread.
css
.panel { transition: transform .2s ease, opacity .2s ease; }
.panel--hidden { transform: translateY(8px); opacity: 0; }
@media (prefers-reduced-motion: reduce) {
.panel { transition: none; }
}
will-change: transform hints ahead of time, but use it sparingly - each layer costs memory.
