How Browser Reflow and Repaint Slow Down Your Page
Your page loads quickly, then stutters the moment someone scrolls, opens a menu or types in a search box. The network panel looks fine, so the problem is not the download.

Your page loads quickly, then stutters the moment someone scrolls, opens a menu or types in a search box. The network panel looks fine, so the problem is not the download. Most of the time it is reflow and repaint: the browser redoing layout and pixel work far more often than it needs to, sometimes dozens of times in a single frame.
This article explains what each step costs, the code patterns that trigger them, how to find them in DevTools, and the fixes that actually move the numbers. The examples assume a modern Chromium browser, but Firefox and Safari follow the same model with small differences in naming.
Where reflow and repaint fit in the rendering pipeline
After the browser parses HTML and CSS, every frame on screen comes from roughly five stages:
- Style. Work out which CSS rules apply to each element.
- Layout. Calculate the size and position of every box. When this runs again after the first time, it is called reflow.
- Paint. Fill in pixels: text, colors, borders, shadows, images. Running it again is a repaint.
- Composite. Stack the painted layers in the right order and hand them to the GPU.
- Display. Show the frame.
Each stage feeds the next. Change something that affects geometry, like width or font size, and the browser has to run layout, paint and composite. Change only a color and it can skip layout but still repaints. Change only transform or opacity on an element with its own layer and, in many cases, it skips straight to composite. If you want the full journey from request to first pixel, our walkthrough of what happens between typing a URL and seeing a page covers the earlier steps.
At 60 frames per second you have about 16.7 milliseconds per frame, and the browser needs some of that for its own work. In practice your JavaScript and the rendering it triggers should fit in about 10 milliseconds. On a mid-range phone, a single full reflow of a large DOM can take longer than that on its own.
What triggers a reflow
Anything that might change geometry can trigger layout. Common causes include:
- Adding, removing or moving DOM nodes.
- Changing width, height, padding, margin, border, top, left or font size.
- Changing text content, which can change line wrapping.
- Toggling a class that changes display or position.
- Resizing the window or rotating a phone.
- Web fonts finishing loading and swapping in with different metrics.
Reflow is not always global. Browsers try to limit it to the affected subtree. But an element with an unknown size, like a flex container whose children all depend on each other, can spread the work across a large part of the page. CSS containment, via the contain property set to layout or content, tells the browser that changes inside an element cannot affect anything outside it, which keeps reflow local. The same idea underpins CSS container queries, which require containment to work.
Layout thrashing, the real performance killer
One reflow per frame is normal. The trouble starts when JavaScript forces the browser to run layout over and over within a single frame. This is called layout thrashing or forced synchronous layout.
Normally the browser batches your style changes and runs layout once, just before the next frame. But if you change a style and then immediately read a geometry property, such as offsetHeight, offsetTop, clientWidth, scrollTop or the result of getBoundingClientRect, the browser cannot give you a stale answer. It has to run layout right then.
Picture a loop over 200 list items. On each pass it reads the item's height, then sets a new height based on it. That is 200 writes and 200 reads interleaved, so the browser runs layout 200 times in one frame. On a test page with a few thousand nodes, I measured that pattern at around 180 milliseconds on a mid-range Android phone. Splitting it into two loops, one that reads every height and one that writes every height, dropped it to about 6 milliseconds.
The rule is simple: read everything first, then write everything. If you need to react to layout across frames, put reads in one requestAnimationFrame callback and writes in the next, or use a ResizeObserver, which reports size changes at a point where reading is cheap.
Repaint costs more than people assume
A lot of performance advice treats repaint as cheap and reflow as the only thing to avoid. I think that is outdated, and it leads people to miss easy wins.
On a desktop with a fast GPU, a repaint of a small area is cheap. But paint cost scales with the area and with how expensive the pixels are. Large box shadows, blur filters, big gradients and backdrop filter are all expensive to paint, and they get repainted every time anything in their area changes. I have seen pages where a sticky header with a 30 pixel blurred shadow cost more per scroll frame than all the layout work combined.
So do not stop at "no reflow". Check paint as well. A color change on a huge element with a heavy shadow can still drop frames on a phone.
How to find reflow and repaint in DevTools
- Open the Performance panel, set CPU throttling to 4x or 6x slowdown, and record while you scroll or click the slow feature.
- In the main thread track, look for purple Layout blocks and green Paint blocks. A red triangle on a layout block often means forced synchronous layout, and the tooltip names the line of JavaScript that triggered it.
- Open the Rendering tab from the command menu and turn on Paint flashing. Areas that repaint flash green. If the whole page flashes when only a small menu changed, something is repainting too much.
- Turn on Layout Shift Regions to see unexpected movement, which usually comes from late loading images or fonts without reserved space.
Measure before and after every change. Some fixes, like adding will-change everywhere, can make things worse by creating too many layers and using more memory.
Fixes that reliably help
- Animate transform and opacity. Move elements with translate instead of top or left, and fade with opacity instead of visibility toggles. Use will-change only on elements that are about to animate, and remove it afterward.
- Batch DOM reads and writes. Read all geometry first, then apply all changes. Build large lists off-screen or in a document fragment and insert them once.
- Reserve space. Give images and embeds width and height attributes or an aspect-ratio so they do not cause reflow when they load.
- Use containment. Apply contain or content-visibility set to auto on long sections and off-screen widgets so the browser can skip their layout and paint.
- Simplify heavy paint. Replace large blurred shadows with smaller ones or a pre-rendered image, especially on sticky or scrolling elements.
- Respect motion preferences. Cutting animations for users who request it also cuts rendering work, as covered in supporting prefers reduced motion.
Frequently asked questions
What is the difference between reflow and repaint?
Reflow recalculates the size and position of elements, while repaint redraws their pixels. A reflow is always followed by a repaint, but a repaint can happen alone, for example when only a color changes. Reflow is usually more expensive because it can affect many elements at once.
Does changing CSS transform cause a reflow?
No. Transform does not change layout, so the browser can skip the layout step. If the element has its own compositor layer, it can often skip paint too and only composite, which is why transform is the preferred property for animation.
How do I stop layout thrashing in JavaScript?
Separate reads from writes. Read all geometry values like offsetHeight or getBoundingClientRect first, then apply all style changes afterward. For work across frames, schedule reads and writes in separate requestAnimationFrame callbacks or use ResizeObserver.
More in Browsers
Browsers
How the Browser Preload Scanner Finds Resources Early
A team I helped last year had a hero image arriving 1.2 seconds into the load on a page whose HTML had finished downloading in...
Browsers
How CORS Preflight Requests Add an Extra Round Trip
A dashboard I was asked to look at last year loaded in 4.2 seconds against an API that answered every call in 30 ms.
Browsers
How Browsers Limit Connections and Queue Your Requests
Open the Network panel on a page that loads 40 images and you will see a shape that looks like a staircase.