How Browsers Render Pages

The critical rendering path — HTML parsing to DOM, CSSOM, render tree, style, layout, paint and compositing — plus render-blocking resources, reflow and repaint, layout thrashing, the browser's process model and the frame budget.

Intermediate 4 min readLesson 4 of 14 Interview Q&A

Between receiving bytes and showing pixels, a browser runs a pipeline that every front-end performance decision touches. (For the network part — DNS, TCP, TLS, HTTP — see What happens when you type a URL.)

The pipeline

parseparseHTMLDOMCSSCSSOMStylecomputed stylesLayoutgeometryPaintdraw commandsCompositeGPU layers
StageWhat happens
Parse HTML → DOMTokenise HTML and build the Document Object Model tree, incrementally as bytes arrive
Parse CSS → CSSOMBuild the CSS Object Model from all stylesheets
StyleMatch selectors to compute every property of every element (the render tree skips display: none)
Layout (reflow)Compute each box's position and size, starting from the viewport
PaintRecord drawing commands (text, colours, borders, shadows, images) per layer
CompositeRasterise layers into tiles (often on the GPU) and combine them into the final frame

Render-blocking resources

  • CSS is render-blocking: the browser won't paint until the CSSOM is ready (to avoid a flash of unstyled content). Keep critical CSS small; inline it if necessary; load non-critical CSS later.
  • Classic scripts are parser-blocking: <script src> stops HTML parsing until it downloads and runs, because the script might call document.write or read the DOM. Use defer, async or type="module" (HTML).
  • Scripts also wait for preceding CSS (they might read computed styles), so CSS blocks scripts which block parsing.

The critical rendering path is the minimal chain of resources needed for the first paint. Shortening it — fewer render-blocking requests, smaller bytes, fewer round trips — is the core of load performance (Web performance).

HTML
<link rel="preload" href="/fonts/inter.woff2" as="font" type="font/woff2" crossorigin>
<link rel="preconnect" href="https://cdn.example.com">
<link rel="stylesheet" href="/print.css" media="print">   <!-- not render-blocking on screens -->

Updating the page: reflow, repaint, composite

After load, every change (JavaScript, CSS animations, hover) re-runs part of the pipeline. Which part depends on what changed:

ChangeTriggersCost
Geometry: width, height, top, margin, font size, adding DOM nodesStyle → Layout → Paint → CompositeHighest; may affect many elements
Appearance only: color, background, box-shadowStyle → Paint → CompositeMedium
transform, opacity (on a composited layer)Composite onlyLowest; can run on the compositor thread even while JS is busy

That's why smooth animations use transform: translate() instead of animating left, and opacity instead of visibility toggles with layout changes.

Layout thrashing

Reading a layout property (offsetHeight, getBoundingClientRect(), scrollTop) forces the browser to synchronously compute layout if anything changed. Interleaving reads and writes in a loop forces a layout per iteration:

JavaScript
// ✗ Forced synchronous layout on every iteration
for (const el of items) {
  el.style.height = el.offsetWidth / 2 + "px";   // read (layout) → write (invalidate) → read…
}

// ✓ Batch reads, then batch writes
const widths = items.map(el => el.offsetWidth);
items.forEach((el, i) => { el.style.height = widths[i] / 2 + "px"; });

Tools like requestAnimationFrame (run writes just before the next frame) and libraries that schedule reads and writes help. DevTools' Performance panel flags "Forced reflow" in purple.

The frame budget

Displays refresh at 60 Hz (or 120 Hz): 16.7 ms per frame (8.3 ms at 120 Hz). The main thread must run JavaScript, style, layout and paint within that budget, or frames drop (jank). Long tasks (over 50 ms) also delay responses to input — measured by Interaction to Next Paint (INP).

InputJSStyleLayoutPaintComposite0179121416

The main thread is single-threaded and shared with your JavaScript (The event loop). Move heavy work to Web Workers, break long tasks up (scheduler.yield(), setTimeout), and use requestAnimationFrame for visual updates.

Browser architecture

Modern browsers are multi-process for security and stability:

ProcessRole
BrowserUI, navigation, network, storage coordination
Renderer (one per site, sandboxed)HTML/CSS parsing, JS (V8, SpiderMonkey, JavaScriptCore), layout, paint
GPURasterisation and compositing
Network, utility, pluginIsolated services

Site isolation puts each site in its own renderer process, so a compromised or Spectre-exploiting page can't read another site's memory. Inside the renderer, the main thread runs JS and layout, while compositor and raster threads produce frames — so compositor-only animations stay smooth even when the main thread is busy.

Rendering engines: Blink (Chrome, Edge, Opera, Brave), WebKit (Safari, all iOS browsers), Gecko (Firefox).

Key takeaways
  • Pipeline: DOM + CSSOM → style → layout → paint → composite.
  • CSS is render-blocking; classic scripts are parser-blocking — use defer, async or modules.
  • Layout changes are most expensive, paint-only less, transform/opacity cheapest (compositor only).
  • Avoid layout thrashing: batch DOM reads before writes.
  • Keep main-thread work within the 16.7 ms frame budget; offload with workers and split long tasks.
  • Browsers isolate sites in sandboxed renderer processes; compositor threads keep animations smooth.
Interview questions
QWhat is the difference between reflow and repaint?medium

Reflow (layout) recalculates the position and size of elements, triggered by geometry changes such as width, font size, or adding nodes; it can cascade to many elements and is followed by repaint. Repaint redraws pixels for appearance changes like colour or shadow without recomputing geometry. Changes to transform and opacity on composited layers skip both and only re-composite, which is why they're preferred for animation.