What happens between changing the DOM and pixels appearing on screen?
Trace style calculation, layout, paint, rasterization, compositing, and the limits of “GPU accelerated.”
Useful prerequisites
Changing a style in JavaScript does not put pixels on the screen immediately. The browser has several stages to get through: it works out which styles apply, calculates layout, paints content and composites layers into a frame. Knowing which stage your code triggers makes performance problems much easier to diagnose.
Changing a style in JavaScript does not put pixels on the screen immediately. The browser has several stages to get through: it works out which styles apply, calculates layout, paints content and composites layers into a frame. Knowing which stage your code triggers makes performance problems much easier to diagnose.
The quick version
A change to the DOM or to styles can invalidate one or more stages of the rendering pipeline. The browser only re-runs the stages that are actually dirty. Geometry changes usually force layout and paint. Some property changes can skip layout. A few properties (primarily transform and opacity on their own layer) can often be updated by the compositor without repainting. “GPU accelerated” is not free and is not a guarantee of better performance.
Build the mental model
The pipeline is roughly:
- Style — compute the final styles for each element.
- Layout — figure out geometry (size and position).
- Paint — record the drawing commands for each layer.
- Raster — turn those drawing commands into pixel data. Depending on the browser and platform, raster work may run on CPU raster threads or use GPU rasterization.
- Composite — assemble the layers into the final frame.
Not every change walks the whole pipeline. The browser tracks what is invalid. Changing only a paint property (colour, for example) can skip layout. Changing a transform on a layer that is already promoted can sometimes skip both layout and paint and only require a compositor update.
Layer promotion is a trade-off. It can make animations cheap, but each layer costs memory and the compositor has more work to do when many layers are moving. Promoting everything “just in case” is a common way to make a page slower.
Forced synchronous layout is the classic footgun. If you write styles (or change the DOM) and then immediately read geometry (offsetWidth, getBoundingClientRect, etc.), the browser has to flush layout right then so it can give you a correct answer. Doing this in a loop produces layout thrashing.
See it in code
/* Usually compositor-only once the layer exists */
.card {
transform: translateY(4px);
opacity: 0.98;
}
/* Geometry change — layout + paint */
.card {
width: 24rem;
height: auto;
}
A more realistic illustration of thrashing:
// Bad: forces layout on every iteration
items.forEach((item) => {
item.style.width = '50%';
const height = item.offsetHeight; // layout flush
item.style.height = height + 8 + 'px';
});
// Better: separate writes from reads
items.forEach((item) => {
item.style.width = '50%';
});
// one layout
items.forEach((item) => {
const height = item.offsetHeight;
item.style.height = height + 8 + 'px';
});
Even the improved version still causes layout; it just does it once instead of N times.
Where it gets tricky
Reading geometry after a write forces synchronous layout.
This is the most common source of “why is this interaction janky?” bugs. The browser has no choice if you ask for current measurements.
Layer explosion.
Creating dozens or hundreds of composited layers (via will-change, 3D transforms, or certain stacking contexts) increases memory use and can make compositing itself expensive. On lower-end devices this shows up as dropped frames even when the main thread looks idle.
will-change is a hint, not a command.
Over-using it is often worse than not using it. Prefer it for elements that are actually about to animate, and remove it when the animation is done if the element does not need to stay on its own layer.
Paint containment and containment in general.
contain: layout / contain: paint can limit how far invalidation spreads. They are useful, but they also change layout behaviour and can create new stacking contexts. Use them when you understand the trade-off, not as a blanket performance switch.
Subpixel layout and fractional values.
Browsers work in subpixels. Rounding differences, especially with transforms and scrolling, can produce visual gaps or blurry text if you assume integer pixel geometry.
The pipeline is implementation-defined in the details.
Chrome, Firefox, and Safari do not have identical heuristics for layer promotion or paint invalidation. Measure on the browsers and devices that matter to your users.
A common misunderstandings
-
“Anything with
transformis GPU accelerated and therefore fast.”
Only if the element is on its own layer and the animation does not force paint or layout. A transform that is recalculated every frame because of layout changes is still expensive. -
“If I use
requestAnimationFramethe animation will be smooth.”
rAF gives you a chance to update before the next frame. It does not prevent you from doing too much work inside the callback. -
“Painting is the expensive part.”
Layout is often more expensive than paint for complex pages. Always check the Performance panel instead of guessing.
What this changes in an application
Most interaction jank that is not caused by long JavaScript tasks comes from layout thrashing or from too much work in the rendering pipeline. The fixes are usually:
- Batch DOM reads, then batch DOM writes.
- Prefer compositor-friendly properties for continuous animations.
- Measure real user devices, not just a high-end laptop.
- Treat
will-changeand forced layer promotion as tools with costs, not as free optimisations.
Core Web Vitals (especially INP and CLS) are downstream of these pipeline costs. If you understand when you force layout or create extra layers, you have a much clearer path to fixing the metrics that actually affect users.
Questions worth exploring next
- What causes forced synchronous layout, and how do you avoid it?
- Why can
will-change: transformsometimes make a page slower? - How does a stacking context affect painting and compositing?
- When would you reach for CSS containment?
References and next steps
- Rendering performance — still the best practical overview.
- What forces layout / reflow — the classic list of properties and APIs that trigger layout.
- CSS Triggers — quick reference for which properties affect layout, paint, and composite (note that some details have evolved).