How Browsers Render a Page

Follow the critical rendering path: parsing HTML and CSS, building the DOM and CSSOM, layout, paint and compositing.

Beginner · about 3 hours · difficulty 2/5

Learn first: HTTP and HTTPS

Once bytes arrive, the browser engine (Blink in Chrome and Edge, WebKit in Safari, Gecko in Firefox) turns them into pixels. Knowing this pipeline explains most performance advice you will ever read.

The pipeline

  1. Parse HTML into the DOM tree. The parser is streaming, so the page can start rendering before all HTML has arrived.
  2. Parse CSS into the CSSOM. CSS is render-blocking: the browser will not paint until the stylesheets in <head> are loaded.
  3. Scripts: a plain <script> pauses HTML parsing while it downloads and runs. defer runs after parsing, in order; async runs whenever it arrives. Modules (type="module") are deferred by default.
  4. Style and layout: combine DOM and CSSOM into a render tree, then compute every box's size and position.
  5. Paint fills in pixels; composite stacks layers on the GPU.

Why it matters

  • Changing width or top forces layout again (expensive). Changing transform or opacity usually only needs compositing (cheap), which is why smooth animations use them.
  • Reading layout values (offsetHeight) right after writing styles forces a synchronous layout, known as layout thrashing.
  • The JavaScript main thread also handles rendering and input, so long-running scripts make the page feel frozen.

Good enough to move on

You can explain why scripts go at the end of <body> or use defer, why CSS is loaded early, and what "reflow" and "repaint" mean. Record a page load in the DevTools Performance panel once and identify parsing, scripting, layout and paint in the timeline.

Key concepts

  • DOM and CSSOM construction
  • Render-blocking resources
  • script defer, async and module
  • Layout, paint and composite
  • Reflow and layout thrashing
  • Browser engines: Blink, WebKit, Gecko
  • DevTools Performance panel

Mini project

Build a small page with a large stylesheet and a heavy script, record it in the Performance panel, then fix the loading order with defer and measure the difference in first paint.

Check yourself

Why is animating transform cheaper than animating left, in terms of the rendering pipeline?

Free resources