Skip to main content

Command Palette

Search for a command to run...

Compositing

Updated
โ€ข2 min readโ€ขView as Markdown

๐Ÿง  TL;DR โ€” Compositing stitches independently-painted layers back together on their own thread, which is why transform and opacity animations stay buttery smooth even when the main thread is busy.

Compositing is the final step of the rendering pipeline, where the browser takes all the separately painted pieces of the page and combines them into the single image you actually see on screen.

flowchart LR
    A[Parse HTML/CSS] --> B[Render Tree]
    B --> C[Layout]
    C --> D[Paint]
    D --> E[Composite]
    E --> F[Pixels on screen]

๐Ÿงฑ Why split the page into layers

Not every element gets painted directly into one big bitmap. The browser promotes certain elements onto their own layers โ€” separate surfaces that can be moved, faded, or transformed independently.

Elements typically get their own layer when they have:

  • a CSS transform

  • an opacity animation

  • will-change

  • a <video> or <canvas>

Isolating them means the browser can update just that layer instead of repainting everything around it.

๐Ÿงต The compositor thread

Compositing usually runs on its own thread, separate from the main thread that handles JavaScript, styles, and layout. That's what lets a page keep scrolling or animating smoothly even while the main thread is busy.

โšก Tip: This is exactly why transform and opacity are the go-to properties for smooth CSS animations โ€” they can skip layout and paint entirely.

/* compositor-only animation โ€” cheap and smooth */
.card {
  transition: transform 0.2s ease;
}
.card:hover {
  transform: scale(1.05);
}

๐Ÿงฉ Tiles and GPU rasterization

Large layers are often broken into smaller tiles, so the browser can prioritize rasterizing the ones closest to the viewport first. Rasterization for compositing is frequently handed off to the GPU, which is built to move and blend huge numbers of pixels in parallel.

โœ… Key takeaways

  • Paint decides what pixels look like; compositing decides how the pieces come together.

  • Layers let the browser skip re-painting unaffected content.

  • transform and opacity are compositor-only โ€” the cheapest properties to animate.

That's the full trip from HTML and CSS to pixels on your screen: Parsing โ†’ Render Tree โ†’ Layout โ†’ Paint โ†’ Compositing.

#rendering-engine #browsers #css #performance

How Browsers work

Part 4 of 7

In this series I will talk about the inner workings of web browsers. Each episode dives into different aspects of browsers like UI, rendering engine, data persistence and much more.

Up next

Browser Architecture

๐Ÿง  TL;DR โ€” A modern browser isn't one program, it's several separate processes โ€” browser, renderer, GPU, network โ€” talking to each other. Splitting them up is what keeps one crashed tab from taking do