Performance
CSS Transform vs Layout Properties: What Really Triggers Repaint
CSS transform vs layout-triggering properties comes down to which stage of the rendering pipeline a change touches. Transform and opacity are handled by the compositor and skip layout and paint; properties such as width, top and margin invalidate layout and force a repaint. In my builds I animate transform and opacity, then confirm with Chrome DevTools that frames stay under 16.7ms.
The rendering pipeline: style, layout, paint, composite
The browser turns CSS into pixels in four stages: recalculate style, layout, paint and composite. Style resolves which rules apply. Layout computes the geometry of every box — width, height and position relative to its parent — so a change here can ripple through siblings and children. Paint fills pixels into one or more layers: text, backgrounds, borders and shadows. Composite stacks those layers and sends the result to the GPU for display. Transform and opacity are special: once an element sits on its own layer, the compositor can move or fade that texture without touching the earlier stages. That is why a transform animation stays smooth while animating left or top stutters. Knowing which stage a property invalidates is the whole decision.
Which properties trigger layout, paint or compositing
Layout-triggering properties change geometry, so the browser must re-run layout before it can paint anything affected. Classic examples are width, height, top, left, right, bottom, margin, padding, border-width, font-size, display and changes to flex or grid tracks. Widening a flex child can shift every sibling, and a font-size change reflows the text around it. In contrast, transform and opacity do not affect the geometry of any other element — they move or fade the finished box. background-color and color are paint-only: no layout, but still a repaint. The rule I use in a build is to reserve geometry properties for state changes that happen once, and use compositor properties for anything that repeats every frame.
- Layout: width, height, top/left/right/bottom, margin and padding
- Layout: font-size, display, border-width and flex or grid track changes
- Paint only: color, background-color, visibility and box-shadow
- Compositor only: transform and opacity
- Transform affects no sibling because it changes no layout geometry
Paint invalidation and why it costs more than you think
Paint invalidation is the cost people underestimate. When a property changes, the browser records a damage rectangle and repaints the affected region of a layer, then composites again. A small repaint is cheap; a full-width repaint of a complex subtree with shadows, gradients and text is not. Layout changes are worse because they usually produce a larger damage area — widening a container can invalidate all of its children. Compositor-only changes skip this entirely: the layer texture already exists, and the GPU just transforms it. That is why a 300px square animated with translateX feels effortless while the same square animated from left: 0 to left: 300px eats frame time. I treat every per-frame repaint as a bug to be proven innocent in DevTools.
- The damage rectangle grows with the element and its descendants
- Layout changes usually invalidate more area than paint-only changes
- A compositor animation reuses an existing texture with no repaint
- Animated box-shadow, gradients and filters force repeated paint work
Compositor layers: promotion, will-change and the memory trade-off
For transform and opacity to skip paint, the element needs its own compositing layer. Browsers promote some elements automatically, but you can request promotion with will-change: transform or the older translateZ(0) and translate3d(0,0,0) technique. Promotion is not free: each layer is a texture held in GPU memory, roughly width × height × 4 bytes for RGBA, plus overhead. Promote a dozen full-screen layers and you spend both memory and compositing time. I add will-change shortly before an animation starts and remove it afterwards, rather than leaving it on static elements forever. Keep promoted layers small, avoid deep nesting of them, and never promote a huge element just to move it a few pixels. Layer count and memory are visible in the Layers panel.
- will-change: transform requests a layer before the animation starts
- translateZ(0) and translate3d(0,0,0) are the legacy promotion trick
- Each layer costs GPU memory: roughly width × height × 4 bytes
- Remove will-change after the animation instead of leaving it site-wide
- Inspect layer count and memory in the Layers panel
Animating the right way, including GSAP and FLIP
When I build motion with GSAP, I animate x, y, scale and rotation, which GSAP writes to transform, rather than left, top, width or height. The force3D setting in GSAP controls whether it adds translate3d for layer promotion. For layout-changing effects I use FLIP: measure the First position of the element, apply the Last state, Invert the difference with a transform, then Play it back to zero. The layout happens once; the animation itself stays on the compositor. A common trap is animating width or height on accordions and carousels, because every frame reflows the neighbours. Animate transform: scale or clip-path instead. I also load GSAP only on the templates that animate, so the library does not cost every visitor.
- Prefer GSAP x/y/scale/rotation over left, top, width and height
- Use FLIP so the layout change happens once, not once per frame
- Animate transform or clip-path instead of width/height on accordions
- Load GSAP only on templates that actually animate
How to audit animation performance in Chrome DevTools
DevTools gives direct evidence. In the Performance panel, record while the animation runs, then inspect the Main track: rows labelled Layout (purple) and Paint (green) mean exactly the work the compositor path avoids. The summary breaks down time spent in Style, Layout, Paint and Composite Layers; a healthy transform animation is dominated by compositing, with no repeating Layout blocks. Open the Rendering panel and enable Paint flashing — repainted regions flash green, so a transform on a promoted layer should produce no flashing at all. Layer borders draw the outlines of compositing layers, and the Layers panel shows the layer tree and its memory cost. Enable CPU throttling at 4× or 6× to expose jank a fast desktop hides.
- Performance panel: watch for repeating Layout and Paint blocks
- Rendering panel: enable Paint flashing and Layer borders
- Layers panel: inspect the layer tree and GPU memory per layer
- Throttle CPU 4×–6× to surface missed frames
- Target under 16.7ms per frame to hold 60fps
Trade-offs, accessibility and common mistakes
Compositor animation is not always the right answer. Transformed text can lose subpixel antialiasing and look slightly blurry because the layer is rasterised at its own resolution. Large blur filters, backdrop-filter and animated box-shadow are expensive even when promoted, because they often force repaints. Respect prefers-reduced-motion: wrap CSS animations in a media query and, in GSAP, guard with matchMedia so motion-sensitive visitors get a static state. Measure the result in real conditions — a mid-range Android phone on throttled 4G tells you more than a desktop trace. I am Saif Al Jahan, a WordPress and PHP developer based in Mymensingh, Bangladesh (GMT+6), and webdev-saif.com documents how I apply this in production builds.
Frequently asked questions
Is CSS transform really cheaper than animating left or top?
Yes. transform moves an element on the compositor without recalculating layout or repainting pixels, while left and top change geometry and force layout, paint and composite every frame. On a busy page that difference is the gap between a steady 60fps and visible jank. I use transform for movement and reserve position properties for one-off state changes.
Does transform ever trigger layout or paint?
On its own, no — transform changes no layout geometry, so siblings and parents are untouched. It can still repaint when the element is not on its own compositing layer, or when the browser re-rasterises the layer after scaling text. Promote with will-change: transform before animating, then verify with Paint flashing that nothing repaints.
Why does my transform animation still stutter?
Usually something else is eating the frame. Check the Performance panel for long JavaScript tasks, layout or paint blocks caused by other elements, or expensive filters and shadows on the animated layer. Too many promoted layers also hurt. Apply CPU throttling to reproduce the jank, then remove suspects one at a time until the trace shows compositing only.
What is will-change and should I add it everywhere?
will-change is a hint that tells the browser a property is about to change so it can promote the element early. It is not a free speed boost: every promoted layer consumes GPU memory. Add it just before an animation and remove it when the animation ends. Leaving it on dozens of static elements increases memory and can make performance worse.
How do I see paint invalidation in Chrome DevTools?
Open DevTools, go to the Rendering panel and enable Paint flashing, then trigger the interaction. Green flashes mark regions the browser repainted. A transform on a promoted layer should flash nothing; animating width or background-color lights up the affected area. The Performance panel adds timing detail with Paint and Layout rows for each frame.
Should I avoid CSS animations altogether?
No. Animate compositor-friendly properties — transform and opacity — and keep geometry changes for rare state transitions. Use prefers-reduced-motion to offer a static alternative. The goal is not zero animation but no repeated layout or paint during the animation. I check the frame trace rather than guessing, because the surrounding DOM decides whether a change is cheap.