Browser Rendering
DOM, CSSOM, render tree, layout, paint, and composite stages
How Browsers Render Pages
From HTML bytes to pixels on screen
When your browser receives HTML from a server, it goes through a multi-step process to convert that text into the visual page you see. This process, called the Critical Rendering Path, involves parsing, tree construction, layout calculations, and painting pixels.
Understanding this pipeline helps you write more performant code. Each stage has performance implications, and knowing what triggers expensive operations like layout and paint helps you avoid janky animations and slow page loads.
The Critical Rendering Path
The complete pipeline from HTML to pixels
Browser Rendering Pipeline
Watch how the browser transforms code into visual content
Browser receives HTML bytes and begins parsing into tokens
Render Blocking
CSS is render-blocking - the browser won't paint until CSSOM is complete. Put critical CSS inline and defer non-critical styles.
GPU Acceleration
Use transform and opacity
for animations - they skip Layout and Paint, going straight to Composite.
DOM Construction
Parsing HTML into a tree structure
Building the Document Object Model
The browser parses HTML bytes into a tree of nodes
3C 68 74...<html>...StartTagElementBrowser receives raw bytes from the network
<html>
<head>
<title>Page</title>
</head>
<body>
<div>
<p>Hello</p>
</div>
</body>
</html>document.documentElement // html
document.head // head
document.body // body
document.querySelector('p') // pRender Tree
Combining DOM and CSSOM for visible elements
Creating the Render Tree
Only visible elements with computed styles make it to the render tree
🌳 DOM
🎨 CSSOM
🎄 Render Tree
Start with the complete DOM tree containing all elements
What's NOT in the Render Tree?
- • Elements with
display: none(completely hidden) - • The
<head>element and its children - • Script and meta tags
- • Note:
visibility: hiddenelements ARE included (they take up space)
Layout & Paint
Calculating positions and drawing pixels
From Boxes to Pixels
Layout calculates geometry, paint fills in the visuals
📐 Layout Phase
Render Tree Input
🖌️ Paint Phase
Waiting for layout...
Layout receives the render tree with computed styles
What Triggers Layout (Expensive!)
- • Changing
width,height - • Changing
padding,margin - • Adding/removing elements
- • Changing
font-size
- • Reading
offsetWidth,offsetHeight - • Reading
getBoundingClientRect() - • Window resize
- • Changing
position
Composite Layers
GPU acceleration and efficient updates
Layer Composition
How the browser uses layers for smooth animations
Simple pages render on a single layer
transform transform: translateX(100px) opacity opacity: 0.5 will-change will-change: transform filter filter: blur(4px) These properties skip Layout and Paint, running at 60fps
width/height width: 200px margin/padding margin: 10px top/left top: 50px font-size font-size: 16px These trigger full Layout, Paint, Composite cycle
What Creates a New Layer?
- •
transform: translateZ(0)ortranslate3d() - •
will-change: transform, opacity - •
position: fixedorposition: sticky - • Elements with CSS
filterorbackdrop-filter - •
<video>,<canvas>,<iframe>elements
Warning: Too many layers consume memory. Use DevTools Layers panel to inspect.
.element { animation: move 1s; }
@keyframes move { to { left: 100px; } }.element { animation: move 1s; }
@keyframes move { to { transform: translateX(100px); } }Key Terms to Remember
Master these terms for technical interviews