Paint and Composite Layers
What You'll Learn
You'll understand how the browser turns layout information into actual pixels on screen and why layering can dramatically improve rendering performance.
The Rendering Pipeline: Paint and Composite
After the browser calculates layout (where elements go), it performs two critical steps:
Painting is when the browser fills in pixels—turning boxes into actual visual content. It draws text, colors, images, borders, and shadows. Think of it like a painter filling in a numbered canvas: the layout provided the outlines, now paint adds the actual colors.
Compositing happens when the browser has multiple layers and needs to combine them in the correct order to produce the final image you see. It's like stacking transparent sheets—each layer might contain different elements, and the compositor arranges them efficiently.
Why Layers Matter for Performance
The browser creates separate composite layers for certain elements (like those with transform, opacity, will-change, or position: fixed). This is powerful because:
- Changes to a layer (like moving it with
transform) don't require repainting—just repositioning the already-painted layer - The GPU can handle compositing very efficiently
- Animations on separate layers run smoothly without blocking the main thread
However, too many layers consume memory. Creating unnecessary layers (over-using will-change) can hurt performance.
In DevTools
The Performance panel shows paint operations as green bars. Large paint areas or frequent repaints signal problems. You can enable "Paint flashing" to see which regions repaint and inspect the Layers panel to visualize how your page is composited.
Key Takeaway: Paint converts layout to pixels (expensive), while compositing combines layers (cheap when GPU-accelerated). Optimize by minimizing paint areas and strategically using composite layers for animations.