Browser Rendering Explained: From HTML to Pixels
Know the path from bytes to pixels, and you know where to look when a page feels slow.
Key takeaways
- The critical rendering path runs HTML and CSS into a render tree, then layout, then paint, then compositing — and a blocking resource anywhere in that chain delays everything after it.
- Layout (reflow) is expensive; compositing (transform/opacity) is cheap. Animate the cheap properties.
- JavaScript that runs on the main thread competes directly with rendering work — long tasks are the most common cause of a page that "loads fast but feels slow."
- Every major performance metric (LCP, INP, CLS) maps to a specific stage of this pipeline, which is why understanding the pipeline makes those metrics stop feeling arbitrary.
The pipeline, stage by stage
A browser turns bytes into pixels through a fixed sequence of stages. Understanding this sequence is the fastest way to stop guessing about performance problems and start diagnosing them.
| Stage | What happens | Triggered by |
|---|---|---|
| Parse | HTML becomes the DOM; CSS becomes the CSSOM | Receiving bytes |
| Style | DOM + CSSOM combine into a render tree of visible nodes with computed styles | DOM or CSSOM changes |
| Layout | The browser calculates the exact position and size of every element | Anything that changes geometry (width, position, content) |
| Paint | Pixels are drawn for each visible element into layers | Anything that changes appearance (color, shadow, background) |
| Composite | Layers are combined on the GPU into the final frame | Transform, opacity changes |
The critical insight is that these stages are not equally expensive, and a change doesn't always start from the top. A transform or opacity change skips layout and paint entirely and goes straight to composite — which is exactly why they're the properties recommended for smooth animation. A change to width or top forces layout to rerun, which forces paint to rerun, which forces composite to rerun. Same visual result, wildly different cost.
Layout thrashing: the classic self-inflicted wound
Watch out: reading a layout property (like offsetHeight) right after writing one (like changing style.width) forces the browser to run layout synchronously, on the spot, instead of batching it. Do this in a loop and you get "layout thrashing" — dozens of forced synchronous layouts in a single frame.
// Thrashing: read forces a flush of the previous write, every iteration
els.forEach(el => {
el.style.width = '100px'; // write
const h = el.offsetHeight; // read — forces layout NOW
});
// Fixed: batch all reads, then all writes
const heights = els.map(el => el.offsetHeight); // all reads first
els.forEach((el, i) => { el.style.width = '100px'; }); // all writes after
Browsers batch layout and style recalculation automatically when they can — but only when your code doesn't force them apart by interleaving reads and writes. This single pattern explains a large share of "why is scrolling janky" bug reports.
Where the main thread becomes the bottleneck
Rendering and JavaScript execution largely share one thread. While a script runs, the browser cannot update layout, respond to input, or paint a new frame. A task longer than 50 milliseconds is classified as a "long task," and long tasks are the primary cause of poor INP (Interaction to Next Paint) — the page looks finished, but a click or tap sits queued behind whatever the main thread is busy doing.
- Break up long tasks — yield back to the browser between chunks of work using
scheduler.yield()or splitting work across microtasks. - Move work off-thread — Web Workers can run heavy computation without blocking rendering, at the cost of not having direct DOM access.
- Defer non-critical scripts — analytics, chat widgets and third-party embeds are common long-task sources; load them after first interaction, not on page load.
How this maps to the metrics you actually measure
| Metric | Pipeline stage it reflects |
|---|---|
| LCP (Largest Contentful Paint) | Time until the largest visible element completes parse → style → layout → paint |
| CLS (Cumulative Layout Shift) | Unexpected layout recalculations after initial render, usually from late-loading images or fonts without reserved space |
| INP (Interaction to Next Paint) | Main-thread availability between an input event and the next painted frame |
Read the full Core Web Vitals checklist for the concrete fixes mapped to each metric above — this article explains the mechanism, that one gives you the action items.
Practical rules that follow directly from the pipeline
- Reserve space for images and ads before they load, so their arrival doesn't force a late layout recalculation (CLS).
- Animate
transformandopacity, notwidth,top, ormargin. - Keep the main thread free near user input — defer third-party scripts until after first interaction where possible.
- Batch DOM reads and writes separately to avoid layout thrashing in loops.
- Prefer
fetchpriority="high"and no lazy-loading on your largest above-the-fold image, since it usually is the LCP element; see the full image optimization guide for the rest of the format and sizing decisions.
Most "slow page" complaints are actually "blocked main thread" complaints. The pipeline itself is fast; what's usually slow is everything competing with it for the same thread.
Once you can name the stage a symptom belongs to — a jump on load is layout, a jank during scroll is paint or a blocked thread, a laggy click is INP — performance debugging stops being guesswork and becomes a lookup.
Frequently asked questions
Why is a transform animation cheaper than animating width?
Transform and opacity changes skip the layout and paint stages entirely and go straight to compositing, which the GPU handles efficiently. Changing width or top forces layout, paint and composite to all rerun.
What counts as a long task?
Any main-thread task longer than 50 milliseconds. Long tasks block the browser from responding to input or updating the frame, which is the primary cause of poor INP scores.
Does the pipeline explain Cumulative Layout Shift?
Yes — CLS happens when layout is recalculated unexpectedly after initial render, typically because space wasn't reserved for an image, ad or web font before it loaded in.