The Browser's Rendering Pipeline
What you'll learn: How browsers turn your code into pixels—and why some animations are smooth while others are janky.
The Three-Stage Pipeline
Every time you change the DOM, the browser goes through up to three stages:
-
Layout (Reflow): Calculates where elements sit on the page—their size, position, and relationship to other elements. Changing
width,height,margin,padding, ordisplaytriggers this. -
Paint: Fills in the visual details—colors, shadows, borders, text. Changing
color,background,box-shadow, orborder-radiustriggers this (but skips layout if size/position don't change). -
Composite: The browser layers painted elements and sends them to the GPU. Only changing
transformoropacitytriggers this—the cheapest operation.
Why Some Animations Are Expensive
Analogy: Think of rearranging a room. Moving furniture (layout) requires measuring everything again and figuring out what fits where. Repainting walls (paint) is cheaper—nothing moves, but you still need to redo the visuals. Sliding a glass table without lifting it (composite) is cheapest—you're just moving existing layers.
When you animate margin-left, the browser recalculates layout every frame (expensive). Animating background-color only repaints (better). Animating transform: translateX() only composites (optimal—60fps smooth).
The Golden Rule
Stick to animating transform and opacity whenever possible. These properties bypass layout and paint, going straight to composite. That's why all your animation libraries (Framer Motion, React Spring, GSAP) default to transforms for movement—they know the rendering pipeline.
Key Takeaway: The browser's rendering pipeline has three stages—layout, paint, and composite. Animating properties that only trigger compositing (transform, opacity) is dramatically cheaper than those forcing layout recalculations.