From URL to Pixels: The Rendering Pipeline
Follow a page load through DNS, TCP, TLS and the first byte, then through parsing into the DOM and CSSOM and the style, layout, paint and compositing stages that produce the first frame.
Contentsand lesson path
On this page
- Why it matters
- From URL to first byte
- Parsing: HTML becomes the DOM, CSS becomes the CSSOM
- Style, layout, paint, composite
- Check your understanding
- Apply it
- Review prompt
Lessons of How Browsers Render Pages
- From URL to Pixels: The Rendering Pipeline Concept · 25 min
- What Blocks the First Paint and How to Unblock It Worked example · 20 min
- The Main Thread, Long Tasks and Layout Thrashing Concept · 20 min
- Lab: Record and Read a Page-Load Trace Lab · 30 min
- Check: Annotate a Waterfall and a Flame Chart Knowledge check · 8 questions
What you will learn
- Trace a page load from navigation request to first paint: HTML parsing, DOM and CSSOM construction, style, layout, paint and compositing.
01. Why it matters
Between typing a URL and seeing the first pixels, the browser does a fixed sequence of work: resolve a name, open a connection, fetch the HTML, parse it into a tree, match styles, compute geometry and paint. Every performance problem you will ever debug lives in one of those stages, and each stage has its own tools for observing it. When someone says "the page feels slow", the first useful question is "which stage?".
The stages also explain the rules you may already have met, such as "stylesheets block rendering" or "prefer transform over top for animation". Those rules are not folklore; each one follows from what a stage consumes and produces. In this lesson you will walk the pipeline and measure it on a page of your own, so the stages become something you have seen rather than a diagram you have memorised.
02. From URL to first byte
Before the browser can ask for a page, it needs an address. A DNS lookup turns the host name into an IP address. Then comes a TCP connection, the transport channel that all the requests will travel over. If the site uses HTTPS — practically all do — a TLS handshake secures that channel before anything is sent over it. Only then does the browser send the HTTP request and wait. The time from sending the request to receiving the first byte of the response is the server wait, and it mostly measures the server and the network between you and it. The time to first byte (TTFB) metric reported by web.dev, Lighthouse and the Chrome UX Report is wider: it is measured from the start of navigation, so it also includes redirects, DNS, connection and TLS time. The script below isolates the server wait in its request to first byte row.
You can read all of these phases from the Navigation Timing entry of any page. The script below was run in the DevTools Console of a small test page (the Console supports top-level await); it ran against a local server, so the output shows what a loopback load looks like:
const nav = performance.getEntriesByType('navigation')[0];
const rows = [
['DNS lookup', nav.domainLookupEnd - nav.domainLookupStart],
['TCP connect', nav.connectEnd - nav.connectStart],
['TLS setup',
nav.secureConnectionStart > 0
? nav.connectEnd - nav.secureConnectionStart
: 0],
['request to first byte', nav.responseStart - nav.requestStart],
];
await new Promise((resolve) => {
if (document.readyState === 'complete') resolve();
else addEventListener('load', resolve, { once: true });
});
const paints = await new Promise((resolve) => {
const observer = new PerformanceObserver((list) =>
resolve(list.getEntries()));
observer.observe({ type: 'paint', buffered: true });
});
const fcp = paints.find((e) => e.name === 'first-contentful-paint');
rows.push(['first contentful paint', fcp.startTime]);
for (const [name, ms] of rows) {
console.log(name.padEnd(28) + Math.round(ms) + ' ms');
}DNS lookup 0 ms
TCP connect 0 ms
TLS setup 0 ms
request to first byte 1 ms
first contentful paint 28 msThe zeros are honest: the page was served from the same machine, so there was no name to resolve, no network to cross and — served over plain http:// — no TLS handshake at all. On a real site each of those phases costs real time: tens of milliseconds for DNS and the connection setup, more if the server is far away or slow to answer. The first contentful paint, by contrast, is work the browser does locally, which is why it appears even on a loopback load.
One useful habit follows from this table: when a page is slow, split the wait into before the first byte and after the first byte. Nothing in your HTML, CSS or JavaScript can make the first byte arrive earlier — the document has to arrive before the browser even knows what resources it needs.
03. Parsing: HTML becomes the DOM, CSS becomes the CSSOM
The response is a stream of bytes that the browser parses according to the rules of the HTML standard. Parsing turns the markup into the DOM: a live tree of objects, one for every element and text run. Parsing is incremental — the tree grows while the bytes are still arriving — which is why a page can start showing content before the document has fully downloaded.
In parallel, the browser fetches and parses CSS into the CSSOM, the tree of style rules. When a stylesheet takes a long time to arrive, everything else waits for it, for a reason you will see in the next section: painting needs both trees. (This is also where the markup habits from semantic HTML pay off: the parser builds a better tree from elements used by their meaning.)
The browser does not sit idle while CSS downloads. The preload scanner races ahead through the raw markup and starts fetching images, scripts and stylesheets it finds, so the requests are queued early even though the parser itself is still working through the first part of the document.
DOM tree CSSOM rules
html html { font-size: 16px }
|-- h1 "Harbour notes" body { font-family: system-ui, ... }
|-- p.lede "Tide times ..." .lede { font-size: 1.25rem }
'-- table.tide-table .tide-table { width: 100% }
render tree: the DOM nodes that paint, each carrying its matched
style -> then layout gives each one geometry -> then paint04. Style, layout, paint, composite
With the DOM and the CSSOM in place, the browser can produce the first frame in four steps:
- Style (also called recalculation): for every element, match the CSS rules that apply and combine them into computed values — this is the cascade you studied in CSS selectors and rule matching, now running at full scale.
- Layout: walk the styled tree and compute the geometry — the position and size of every box.
- Paint: fill the boxes in: text, backgrounds, borders, shadows, drawn into layers.
- Composite: assemble the layers on screen, a job the browser can hand to the GPU.
Each stage consumes the output of the one before it, which is why the order is fixed and why the cost of a change depends on which stage it reaches. Changing width invalidates geometry, so layout runs again and paint follows. Changing color leaves geometry intact, so only paint runs. Changing transform or opacity can usually skip both and be composited alone. This dependency chain is the single most useful thing to remember from this lesson.
The style stage explains what getComputedStyle returns: not what you wrote, but the value after the cascade has resolved it (the standard calls it the resolved value; for font-size that is the computed value in pixels):
getComputedStyle(document.querySelector('.lede')).fontSize20pxThe stylesheet said 1.25rem; the browser answers 20px, because 1.25 × the root size of 16 px is 20 px. That is the style stage made visible: relative units are resolved, inherited values are filled in, and every element ends up with a complete set of concrete values that layout can consume. (The CSS behind this page is deliberately simple — see the box model, flow and display for how those boxes get their geometry.)
05. Check your understanding
06. Apply it
The skill's practice task asks you to trace a slow page and report before-and-after timings. Start by running the measuring script from this lesson against a real website with DevTools open:
- Paste the script into the Console of a content-heavy page (a news site or documentation site works well).
- Note which network phase dominates: TTFB over a few hundred milliseconds points at the server; large DNS or connection times point at the network path.
- Open the DevTools Network panel, enable throttling, reload, and compare the phases against your unthrottled run.
Keep the numbers — the lab later in this skill (Lab: Record and Read a Page-Load Trace) builds directly on this habit and turns it into a before-and-after report.
07. Review prompt
Without looking back, name the network phases in order and say what each one measures. Then list the four rendering stages in order, what each consumes from the previous one, and which stage a change to width, a change to color, and a change to transform each reach. Finally, explain why the browser can paint before images arrive but not before matching stylesheets arrive.
References
Your progress
Reading state
Sign in to save that you finished reading this lesson.
Prove this skill
8 questions · about 6 minutes · scored automatically. Marking a lesson as read never demonstrates a skill.