Skip to main content

Command Palette

Search for a command to run...

How a Web Browser Actually Works

From typing a URL to painting pixels—a beginner-friendly guide to browser internals.

Published
7 min read
How a Web Browser Actually Works
H
CS Graduate | Technical Writing | Software development | 20K+ impressions

Title: Beyond the Magic Window: How a Web Browser Actually Works
Subtitle: From typing a URL to painting pixels—a beginner-friendly guide to browser internals.
Meta Description: Discover what happens behind the scenes when you type a URL. Learn how web browsers parse HTML and CSS, build the DOM, and paint pixels on your screen.


What happens when you type a URL into your address bar and press Enter?

For most of the world, the answer is simple: the browser thinks for a second, and then the website appears. The browser is treated as a magic window. You ask it for a page, and it shows you a page.

But as a web developer, you can’t afford to view the browser as magic anymore. You are building the things that live inside it. To write good HTML, CSS, and JavaScript, you need to understand the machine that reads your code.

A browser is not a single monolith; it is a massive, coordinated collection of software components working together at breakneck speed. Let’s break down exactly how it turns raw code into the pixels on your screen.


The Anatomy of a Browser

Before we look at the flow of data, let's map out the major parts of the browser.


   +-------------------------+
   |     User Interface      | <-- Address bar, back button, bookmarks
   +-------------------------+
               |
   +-------------------------+
   |     Browser Engine      | <-- The coordinator
   +-------------------------+
               |
   +-------------------------+
   |    Rendering Engine     | <-- The factory (Blink, Gecko, WebKit)
   +-------------------------+
      /        |         \[Networking] [JS Engine] [UI Backend]
  • The User Interface: Everything you interact with that isn't the webpage itself. The tabs, the refresh button, the address bar.

  • The Browser Engine: The traffic cop. It sits between the User Interface and the Rendering Engine, passing messages back and forth.

  • The Rendering Engine: The star of the show. This is the part that actually reads HTML and CSS and draws the webpage. (You might hear names like Blink for Chrome/Edge or Gecko for Firefox—these are rendering engines).

  • Networking: The fetching layer. It makes the HTTP requests to the internet to download your files.

We are going to focus entirely on what the Rendering Engine does.


Step 1: Getting the Data

When you press Enter, the Networking layer reaches out to a server and downloads a file. Usually, this is an HTML document.

But the browser doesn’t receive a neatly formatted text file. It receives raw bytes of data over the network (like 01001000 01100101...). It translates those bytes into characters, which form the tags and text you wrote in your code editor.

But a long string of text is useless to a computer. To do anything with it, the browser has to parse it.


Interlude: What is Parsing?

Parsing is the act of taking a string of text and breaking it down into a structured format that a computer can understand and manipulate.

Imagine a simple math expression: 3 + (4 * 2).

When you read that, your brain parses it. You don't just read it left-to-right as "three plus open parenthesis four..." You understand the underlying structure. You know that (4 * 2) is a sub-group, and the result of that group is added to 3.

If we mapped your brain's logic, it would look like a tree:

      [ + ]
      /   \
    [3]   [ * ]
          /   \
        [4]   [2]

The browser does the exact same thing with your code. It reads your text, figures out the vocabulary, and builds a tree out of it.


Step 2: HTML and the DOM Tree

As the rendering engine reads your HTML text, it encounters tags like <html>, <body>, and <p>. It parses these tags and builds a massive structure called the DOM (Document Object Model).

The DOM is a tree structure representing your page. Every HTML tag becomes a "node" (a leaf or branch) on this tree.

[ HTML text ] 
<html>
  <body>
    <p>Hello World</p>
  </body>
</html>[ DOM Tree ]
       html
        |
       body
        |
        p
        |
  "Hello World"

The DOM is crucial because it gives the browser a map of the page's structure. It also gives JavaScript a way to interact with the page later.


Step 3: CSS and the CSSOM

HTML only provides the skeleton. While the browser is building the DOM, it will likely spot a <link> tag pointing to a CSS file. The Networking layer fetches that CSS file.

Just like HTML, CSS is just a string of text. The browser parses it and builds a separate tree called the CSSOM (CSS Object Model).

The CSSOM maps out all the styling rules. It calculates which styles apply to which elements, keeping track of inheritance (e.g., if you set a font size on the <body>, the CSSOM notes that the <p> tags inside it should inherit that size).

CSS Text --> Parse --> CSSOM Tree (Style Rules)

Step 4: The Render Tree (The Marriage)

Now the browser has two distinct trees:

  1. The DOM (what the page is).

  2. The CSSOM (how the page should look).

The browser combines these two into a single structure called the Render Tree.

The Render Tree is the ultimate blueprint. It contains everything that needs to be drawn on the screen.

Here is a vital distinction: The DOM contains everything in your HTML. The Render Tree only contains what is visible. For example, the <head> tag is in the DOM, but it's not in the Render Tree because it doesn't show up on screen. If you write display: none; on a <button> in your CSS, that button exists in the DOM, but it is completely left out of the Render Tree.


Step 5: Layout (Reflow)

At this point, the browser knows exactly what nodes it needs to display and what styles they have. But it doesn't know where they go.

This is the Layout phase (sometimes called Reflow).

The browser starts at the root of the Render Tree and calculates the exact geometry of every element. It uses math to figure out:

  • How wide is the viewport?

  • This <div> is 50% width, so how many pixels is that?

  • This text wraps to three lines, so how tall does its container need to be?

During Layout, the browser figures out the exact coordinates (x, y) and dimensions (width, height) for every single box on the page.


Step 6: Paint and Display

We have the structure, the styles, and the geometric coordinates. The final step is to actually draw the pixels. This is the Paint phase.

The browser converts the layout boxes into actual pixels on the screen. It paints the backgrounds, the text colors, the borders, and the shadows. It does this by sending instructions to the UI Backend (which interfaces with your computer's graphics card).

Finally, the browser composites all these painted pixels together and displays them on your monitor.

The website has arrived.


The Big Picture

When you put it all together, the journey from a URL to a rendered webpage looks like this:

Network Request --> HTML --> DOM \
                                  +--> Render Tree --> Layout --> Paint
Network Request --> CSS  --> CSSOM /

You don't need to memorize the exact algorithms or engine names right now. As a beginner, the goal is simply to build an accurate mental model.

Understanding this flow makes you a better developer. Why is a CSS animation on opacity faster than animating a margin? Because changing a margin forces the browser to recalculate the math for the entire page (Layout), while changing opacity only requires redrawing the pixels (Paint).

The browser isn't magic. It's an assembly line. Once you understand how the line works, you can start building better websites for it.