User Agents

Web browsers and everyday web tech, explained

Browser Rendering Pipeline: What Happens on Enter

· 7 min read · Browsers

In this article
  1. The Starting Line: Navigation and Resource Fetching
  2. Parsing HTML and Building the DOM
  3. Style Calculation: Matching Selectors to Elements
  4. Layout: Calculating Geometry
  5. Paint: Filling in Pixels
  6. Compositing: Putting the Layers Together
  7. JavaScript and the Rendering Pipeline
  8. Frequently Asked Questions

When you press Enter, the browser takes the URL you typed, resolves it to an IP address, fetches the page resources, and then runs a multi-stage rendering pipeline that converts HTML, CSS, and JavaScript into pixels on your screen. This pipeline—parsing, style calculation, layout, paint, and compositing—happens in milliseconds and is the core of how every web page appears.

The Starting Line: Navigation and Resource Fetching

Before any rendering begins, the browser must locate and download the page. If you type a domain like example.com, the browser first checks its cache, then the OS cache, then a DNS resolver to find the corresponding IP address. Once the IP is known, it establishes a TCP connection (often over HTTPS) and sends an HTTP request. The server responds with the HTML document, plus any linked CSS, JavaScript, images, fonts, and other resources. These resources are fetched in parallel where possible, but the HTML is processed incrementally—the browser can start parsing before the full document arrives.

A common misconception is that the browser waits for the entire page to download before showing anything. In reality, modern browsers stream the HTML and begin rendering as soon as they have enough data, which is why you often see a partial page appear quickly.

Parsing HTML and Building the DOM

The first major step in the rendering pipeline is parsing the HTML source into a tree structure called the Document Object Model (DOM). The HTML parser reads tokens like <div>, <p>, and attributes, and constructs nodes for each element. The DOM is not just a copy of the HTML—it is a live, programmatic representation that JavaScript can access and modify.

During parsing, the browser also builds the CSS Object Model (CSSOM) from any linked or inline stylesheets. The CSSOM is a tree of styles that maps selectors to computed styles. Both trees are built in parallel, but the render tree (which combines them) is constructed only after both are ready for the relevant parts of the page.

If the parser encounters a <script> tag without an async or defer attribute, it must pause parsing, execute the JavaScript, and then resume. This is why placing scripts at the bottom of the body or using defer is a common performance recommendation—it avoids blocking the initial render.

Style Calculation: Matching Selectors to Elements

Once the DOM and CSSOM exist, the browser computes the final style for every visible element. This process, often called style calculation or recalc, matches CSS selectors against the DOM nodes. For each element, the browser determines which CSS rules apply, resolves conflicts (based on specificity and source order), and produces a computed style object that includes properties like color, font-size, display, and margin.

This step can be expensive if there are many rules or complex selectors. For example, a selector like div > p:first-child requires checking parent-child relationships. However, modern browsers use optimizations like rule hashing to speed up matching, so the impact is usually minimal unless the page has thousands of rules.

Layout: Calculating Geometry

After styles are computed, the browser performs layout (also called reflow). This step calculates the exact position and size of every element in the viewport. The layout engine walks the render tree (a subset of the DOM that includes only visible elements) and assigns coordinates based on the CSS box model: content, padding, border, and margin.

Layout is a top-down process: the browser starts at the root element and works down, determining how each element affects its children. For example, a <div> with width: 50% will be sized relative to its containing block. The result is a layout tree where every element has a precise rectangle on the screen.

Layout is one of the most performance-sensitive steps. Changing an element’s width or height can trigger a reflow of the entire page, which is why frequent DOM manipulations can cause jank. Modern browsers batch layout updates where possible, but it’s still best to minimize forced reflows (e.g., reading offsetWidth after a style change).

Paint: Filling in Pixels

Once layout is done, the browser knows where everything goes. The next step is painting, where the browser fills in the visual details—colors, borders, text, shadows, backgrounds, and images. The painting process is done in layers (or paint layers) that can be composited independently.

The browser creates a paint record for each layer, which is essentially a list of drawing commands. For example, for a <button>, the paint commands might include drawing a rounded rectangle, then a text string, then a border. These commands are executed by the browser’s rasterizer, which turns them into actual pixels in memory.

Painting is not necessarily done for the entire page at once. The browser only paints the visible portion (the viewport) and may paint more as you scroll. This is why scrolling can sometimes cause a brief flash of white or a delay—the browser is painting new areas on the fly.

Compositing: Putting the Layers Together

The final step is compositing, where the browser combines all the paint layers into the final image you see. This is done by the compositor thread, which takes the layers and applies transformations, opacity, and filters to create the final frame.

Compositing is especially important for animations and scrolling. If you animate a property like transform or opacity, the browser can move a layer around without re-painting it—it just re-composites. This is why CSS transforms are smoother than animating top or left, which trigger layout and paint.

The composited frame is then sent to the GPU (Graphics Processing Unit) for display. The GPU handles the final presentation, including vsync and frame pacing, to ensure smooth 60fps (or higher) refresh rates.

JavaScript and the Rendering Pipeline

JavaScript can interact with the pipeline at any stage. When you modify the DOM or CSS, the browser marks the affected parts as dirty and schedules a re-render. The pipeline is not a one-time process—it runs repeatedly as the page updates.

For example, if you change an element’s style.color, the browser only needs to recalculate styles and repaint—it doesn’t need to redo layout. But if you change style.width, it triggers layout, paint, and possibly compositing. Understanding which properties trigger which stages helps developers write efficient code.

A common performance pitfall is reading layout properties (like offsetHeight) inside a loop that also modifies styles. This forces the browser to flush the layout queue repeatedly, causing a “layout thrashing” slowdown. Instead, batch reads and writes to avoid forcing multiple synchronous layouts.

Frequently Asked Questions

Why does the page sometimes appear blank for a second before showing content?

This usually happens because the browser is waiting for the HTML to be parsed and the first paint to be ready. If the HTML is large or the server is slow, the browser may not have enough content to render. Also, if there are blocking scripts or stylesheets, the browser may delay rendering until they are loaded.

What is the difference between layout and paint?

Layout calculates the geometry—where elements are and how big they are. Paint fills in the visual details—colors, text, images, borders. You can think of layout as drawing the blueprint, and paint as applying the paint to the walls.

Does the browser render the whole page at once?

No. The browser renders the visible portion first and then may render more as you scroll. This is called incremental rendering. It’s why you can see the top of a long page before the bottom has fully loaded.

How can I make my website render faster?

Reduce the number of DOM elements, avoid complex CSS selectors, minify and compress your resources, use async or defer for scripts, and prefer CSS transforms and opacity for animations over layout-triggering properties. Also, consider using a service worker to cache resources.

What is the render tree?

The render tree is a subset of the DOM that includes only the elements that will actually be displayed. Elements with display: none or visibility: hidden are excluded. The render tree is what layout and paint operate on.

Does the pipeline change for different browsers?

Yes, but the general stages are the same. Chrome uses Blink, Firefox uses Gecko, and Safari uses WebKit. Each has its own implementation details, but they all follow the same parsing, style, layout, paint, and composite model.