The Critical Render Path
How browsers turn HTML into pixels: DOM, CSSOM, layout, paint, composite
Skills taught: web.render-pipeline, web.dom, web.cssom, web.render-blocking
The six steps
HTML bytes received
↓
1. Parse HTML → DOM Tree
(Document Object Model: tree of all HTML elements)
↓
2. Parse CSS → CSSOM Tree
(CSS Object Model: which styles apply to which nodes)
↓
3. DOM + CSSOM → Render Tree
(only visible nodes, with all styles resolved)
↓
4. Layout (Reflow)
(calculate exact size and position of every element)
↓
5. Paint (Rasterize)
(draw pixels for each element onto layers)
↓
6. Composite
(combine layers and send to screen)
↓
First visible pixel (First Contentful Paint)
Render-blocking resources
Some resources pause the rendering pipeline. The browser cannot proceed until these resources are downloaded and processed.
<!-- RENDER-BLOCKING (pauses rendering until downloaded + parsed) -->
<link rel="stylesheet" href="styles.css"> <!-- always blocks -->
<script src="analytics.js"></script> <!-- blocks + pauses HTML parsing -->
<!-- NON-BLOCKING -->
<script src="analytics.js" defer></script> <!-- downloads in parallel, runs after HTML parsed -->
<script src="widget.js" async></script> <!-- downloads in parallel, runs when ready -->
<link rel="preload" href="hero.jpg" as="image"> <!-- fetch early, don't block rendering -->
<link rel="preload" href="font.woff2" as="font" crossorigin> <!-- preload critical fonts -->
- CSS always blocks rendering — The browser must have the full CSSOM before it can build the render tree. Put critical CSS in
<head> but keep it small. - Script without defer/async blocks HTML parsing — The parser stops, waits for the script to download and run, then resumes. A slow CDN for one analytics script can blank your page for seconds.
- Fonts block text rendering — Browsers show invisible text until the font loads (FOIT). Use
font-display: swap in @font-face to show system font first.
Tip: Rule of thumb: CSS in <head>. Scripts at end of <body> or with defer. Third-party scripts almost always get async.
Layout vs Paint vs Composite
Changing this CSS property triggers:
width / height / margin / padding / top / left → Layout + Paint + Composite
(most expensive — recalculates positions of other elements too)
color / background / box-shadow / border-color → Paint + Composite
(expensive — pixels must be redrawn)
transform / opacity → Composite only
(cheap — handled by the GPU, no layout or paint needed)
✓ Use transform/opacity for ALL animations
Frequently Asked Questions
What is the difference between reflow and repaint?
Reflow (layout) recalculates the position and size of elements — triggered by changes to geometry (width, height, margin, padding, font-size). It can cascade: changing one element's size may shift others. Repaint draws pixels for visual changes that do not affect geometry (color, background, visibility). Reflow always triggers repaint, but repaint does not always trigger reflow. Both are expensive on the main thread — prefer transform/opacity changes that only trigger compositing.
What does 'render-blocking' actually mean in practice?
The browser shows a completely blank white screen until all render-blocking resources are downloaded and processed. On a fast connection, this is imperceptible. On 3G or a slow CDN, it can mean 3-8 seconds of blank screen. The fix: inline critical CSS (<style> in <head>), use font-display: swap for fonts, add defer or async to scripts, and host scripts on a fast CDN.