Tech

Browser Rendering Explained: From HTML to Pixels

Suggested path: Performance Engineering · View path →

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

5pipeline stages
16.6msbudget per frame at 60fps
50mslong-task threshold

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.

StageWhat happensTriggered by
ParseHTML becomes the DOM; CSS becomes the CSSOMReceiving bytes
StyleDOM + CSSOM combine into a render tree of visible nodes with computed stylesDOM or CSSOM changes
LayoutThe browser calculates the exact position and size of every elementAnything that changes geometry (width, position, content)
PaintPixels are drawn for each visible element into layersAnything that changes appearance (color, shadow, background)
CompositeLayers are combined on the GPU into the final frameTransform, 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

MetricPipeline 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

  1. Reserve space for images and ads before they load, so their arrival doesn't force a late layout recalculation (CLS).
  2. Animate transform and opacity, not width, top, or margin.
  3. Keep the main thread free near user input — defer third-party scripts until after first interaction where possible.
  4. Batch DOM reads and writes separately to avoid layout thrashing in loops.
  5. 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.

  • #Web Performance
  • #Browser
  • #Rendering

Latest updates

The four most recent posts across StackSignal.

All posts