Full answer
The path from a response to pixels has these steps:
- Parse HTML into the DOM. The parser reads bytes, makes tokens and builds nodes. It can build the DOM while the response is still arriving.
- Parse CSS into the CSSOM. This is a tree of style rules. The browser needs the full CSSOM of the stylesheets it has found before it can paint, because a later rule can change an earlier one.
- Build the render tree. It joins DOM nodes with their computed styles. Only visible boxes are in it. An element with
display: noneis in the DOM, and it is not in the render tree. An element withvisibility: hiddenis in the render tree and takes space. - Layout. The browser computes the size and position of each box.
- Paint. It turns boxes into draw operations: text, colour, borders, images.
- Composite. Layers are drawn on the GPU in the right order. Elements with their own layer can move without a new paint.
What blocks:
- A stylesheet in the head blocks rendering until it loads, because painting without it would show unstyled content. It also blocks scripts that come after it, since a script may read styles.
- A classic script without
asyncordeferblocks the HTML parser while it downloads and runs. - Fonts do not block the first paint by default, but text can be invisible or swapped depending on
font-display.
To speed it up: send less CSS first, inline the small critical part, use defer for scripts, and do not hide the page behind a client-side data fetch.
The snippet shows the DOM and render tree difference. Both elements exist in the DOM, but only one of them has a box.
html
<p id="gone" style="display: none">Removed from the render tree</p>
<p id="hidden" style="visibility: hidden">Invisible but still takes space</p>
<script>
window.report = {
goneInDom: !!document.getElementById('gone'),
goneBoxes: gone.getClientRects().length,
hiddenBoxes: hidden.getClientRects().length,
};
console.log(JSON.stringify(report));
</script>Run in headless Chrome 156 through Playwright. Two full runs gave the same results. Checked in headless Chrome. The check reads the number of boxes for each element. Painting and compositing are not visible in this check.
Key points
- HTML becomes the DOM, CSS becomes the CSSOM, together they form the render tree.
- Layout computes geometry, paint draws it, composite assembles layers.
- display none is in the DOM but not in the render tree. visibility hidden still takes space.
- CSS blocks rendering. Synchronous scripts block parsing.
Common mistakes
- Saying the DOM and the render tree are the same thing.
- Thinking that scripts at the end of the body block painting of earlier content, when only the later content is waiting.
- Forgetting that a stylesheet delays scripts that follow it.
- Describing JavaScript as always blocking. async and defer scripts do not block parsing.
Follow-ups
- Which of these steps run again when a class name changes?
- Why can the browser start painting before the whole HTML file has arrived?
- How does a media attribute on a link change blocking?
Tips
- Draw the six steps in order and name one blocker for each stage.
- Use the display none and visibility hidden pair as the quick proof.