How Browsers Render a Web Page – A Frontend Developer’s Guide
How Browsers Render a Web Page – A Frontend Developer’s Guide
By Jyothsna Dannana
As frontend developers, we spend most of our time working with frameworks like Angular or React. We focus on components, state, routing, and UI logic.
Understanding how browsers render a web page helps you:
-
Write faster applications
-
Avoid performance issues
-
Debug UI problems easily
-
Think like a senior frontend developer
Let’s break it down step by step.
1️⃣ What Happens When You Enter a URL?
When a user types a URL in the browser and presses Enter, the browser doesn’t magically show the page.
Here’s what really happens:
-
The browser sends a request to the server
-
The server responds with HTML, CSS, and JavaScript files
-
The browser starts processing these files
-
The page is rendered on the screen
This whole workflow is known as the browser rendering process.
📊 High-Level Browser Flow
2️⃣ Parsing HTML – Creating the DOM
The browser starts by reading the HTML file from top to bottom.
-
Every HTML tag is converted into a JavaScript object
-
These objects are connected together in a tree-like structure
-
This structure is called the DOM (Document Object Model)
📌 The DOM represents the structure of the web page.
📊 DOM Creation Diagram
Whenever JavaScript updates the page, it is actually modifying this DOM.3️⃣ Parsing CSS – Creating the CSSOM
At the same time, the browser processes CSS files.
-
CSS rules are parsed and converted into another tree structure
-
This structure is called the CSSOM (CSS Object Model)
📌 The CSSOM defines how elements should look.
Important Note:
CSS is render-blocking.
The browser waits until CSS is fully loaded before displaying the page.
📊 CSSOM
4️⃣ Creating the Render Tree (DOM + CSSOM)
Now the browser combines:
-
DOM (structure)
-
CSSOM (styles)
This combination creates the Render Tree.
* The Render Tree contains only visible elements
* Elements with display: none are excluded
📊 Render Tree Diagram
5️⃣ Layout (Reflow) – Calculating Size & Position
Once the render tree is ready, the browser calculates:
-
Width and height of each element
-
Exact position on the screen
This step is called Layout (also known as Reflow).
6️⃣ Painting – Drawing Pixels on the Screen
After layout, the browser starts painting the page.
Painting includes:
-
Text
-
Colors
-
Backgrounds
-
Borders
-
Images
-
Shadows
7️⃣ JavaScript Execution & Page Updates
JavaScript runs during and after the rendering process.
-
JavaScript can change DOM elements
-
JavaScript can update styles
-
These changes may trigger new layout or paint cycles
Example:
This causes:
-
Layout recalculation
-
Repainting of the page
8️⃣ Reflow vs Repaint
Understanding this is critical for frontend performance.
🔹 Reflow
-
Happens when layout changes
-
Browser recalculates positions and sizes
-
Expensive operation
Triggered by:
-
Changing width or height
-
Adding/removing DOM elements
-
Changing font size
🔹 Repaint
-
Happens when visual styles change
-
Layout stays the same
-
Less expensive
Triggered by:
-
Changing color
-
Changing background
-
Changing visibility







Comments
Post a Comment