The browser and React · Question 10 of 50

What is the difference between reflow and repaint? Why is layout thrashing slow?

What they're checking

The rendering pipeline, and practical frontend performance.

The answer

Changing geometry (width, height, position, font size, adding elements) forces layout, also called reflow: the browser recalculates sizes and positions, often for much of the page. Changing only looks (colour, background, visibility) needs a repaint, which is cheaper. transform and opacity can skip both and run on the compositor, which is why animations should use them.

Layout thrashing is reading a layout value such as offsetHeight right after writing a style, in a loop: every read forces a fresh layout. Read everything first, then write.

// thrashing: every read forces a new layout
items.forEach((el) => {
  el.style.width = box.offsetWidth + 'px'
})
// better: read once, then write
const w = box.offsetWidth
items.forEach((el) => { el.style.width = w + 'px' })

The picture

style ─▶ LAYOUT (reflow) ─▶ PAINT ─▶ COMPOSITE
width, top, font ──┘           │           │
colour, background ────────────┘           │
transform, opacity ────────────────────────┘   cheapest
The follow-up they'll ask

How do you find it?

Show the answer

The Performance panel in Chrome DevTools: long purple Layout blocks, and warnings about forced reflow.

Your progress stays on this device.