Course contentsShow
← Web Development
Lesson 543 of 2,9829. CSS Transitions and AnimationsFree lesson

Composite-Only Animations

Use transform and opacity for GPU-accelerated animations that skip layout and paint.

Composite-Only Animations

You'll learn why transform and opacity create the smoothest, most performant animations in CSS.

The Fast Lane for Animations

Remember how the browser's rendering pipeline has multiple stages—layout, paint, and composite? Most CSS property changes force the browser through all these expensive steps. But two special properties, transform and opacity, can skip straight to the composite stage, letting the GPU handle the animation entirely.

When you animate transform or opacity, the browser doesn't need to recalculate where elements are positioned (layout) or redraw their pixels (paint). Instead, it treats the element as a separate layer and just moves or fades that pre-rendered layer—like sliding transparent sheets of glass rather than redrawing the entire scene.

Why This Matters

Animating properties like width, height, top, or margin triggers reflow and repaint—expensive operations that can cause janky, stuttering animations, especially on lower-powered devices. Composite-only animations using transform and opacity run at silky-smooth 60fps because the GPU excels at this type of work.

/* Slow - triggers layout and paint */
.box:hover {
  left: 100px; /* Avoid animating position properties */
  width: 200px; /* Avoid animating size properties */
}

/* Fast - composite-only */
.box:hover {
  transform: translateX(100px); /* Use transform instead */
  opacity: 0.5; /* Opacity is also GPU-accelerated */
}

Think of it like moving a photo on your desk versus redrawing the entire photo—one is instant, the other takes real work.

Key Takeaway: For the smoothest animations, stick to transform (for movement, scaling, rotation) and opacity (for fading)—they're the only properties that consistently bypass layout and paint to run on the GPU's fast track.