Sharing notes from my ongoing learning journey — what I build, break and understand along the way.
How Browsers Work: Understanding Rendering, Parsing, and Repainting
How Browsers Work: Render, Parse, and Repaint Explained
Every webpage we see is the result of a complex process happening behind the scenes inside our browser. Clicking a link and seeing a page appear looks simple — but under the hood, dozens of things are happening.
In this post, I’ll break down how browsers actually render a web page, step by step.
1. URL → Request → Response
When you visit a website, the browser takes the URL and looks up its IP address via DNS.
It then sends an HTTP request to that address.
The server responds with HTML, CSS, JS, images, and other assets, which the browser must now process.
That’s when the real “stage setup” begins.
2. HTML Parsing and the DOM
The browser reads the HTML line by line — this process is called parsing.
Every tag becomes a node in the DOM (Document Object Model) — a tree-like structure representing the page in memory.
As the browser encounters CSS or JavaScript files:
- It downloads CSS and builds the CSSOM (CSS Object Model).
- JavaScript can be blocking, meaning it might pause DOM construction — unless it’s loaded with
deferorasync.
3. Building the Render Tree
Now the browser has two main structures:
- The DOM (what the page is)
- The CSSOM (how it should look)
These are combined into the Render Tree, which determines what will actually appear on screen and with what styles.
For example, a <div>’s background color, size, and font information are merged here.
4. Layout (Reflow)
Once the render tree is ready, the browser calculates each element’s size and position on the page.
This stage is called layout or reflow.
It considers things like screen size, margins, padding, and positioning rules.
If JavaScript or CSS later changes an element’s dimensions, the layout process runs again — which is expensive performance-wise.
5. Painting
Next, the browser paints each node — converting styles (colors, borders, shadows) into actual pixels.
This happens in layers, and often the GPU is used for smoother rendering, especially in animations or 3D effects.
6. Compositing and Repaint
For complex pages (sticky headers, scrolling sections, animations), the browser composites multiple layers — stacking them in the correct order.
If an element’s appearance changes (like color), that triggers a repaint.
If its position or size changes, that requires a reflow + repaint, which is much heavier.
7. Why Optimization Matters
Frequent reflows and repaints slow down performance.
To keep things smooth:
- Animate only
transformandopacityproperties - Use
will-changecarefully - Batch DOM manipulations together
- Avoid unnecessary CSS rules that trigger layout recalculations
In Short
Browsers go through an intricate pipeline — parse, render, layout, paint, composite — just to show a simple page.
Understanding this flow helps us go beyond “it works” and build web experiences that are faster, smoother, and more user-friendly.
