SPEED & PERFORMANCEAI-REVIEWED

How does a browser render a web page?

Useful first: HTTP · optional, not a requirement

Choose your depth

Stay with the essentials, or look closer.

Simple explanation
3 min read · estimate

YOUR GOALSeparate receiving a page's files from arranging and displaying their contents.

Turn page instructions into something you can read.

The browser builds the view

HTML describes content such as headings and paragraphs. CSS supplies rules for their appearance. Your browser reads these instructions and works out the view on your screen; the downloaded HTML is not a ready-made screenshot.

Imagine a recipe page. It contains a title, an ingredient list, and a photo. A narrow phone screen may wrap the title onto two lines while a wider window fits it on one. The browser has to arrange the content for the available space.

[1] [3]

A page can change after it first appears

The browser can start processing HTML as it arrives and fetch other resources along the way. Showing some text does not mean every image or script has finished loading.

If a photo arrives and its space was not reserved, content below it can move. Resizing the window can also require a new arrangement. Rendering continues as the page changes.

[1]

Why can a page look ready but respond slowly?

A visible button is not a promise of an instant response. The browser's main thread handles much of a page's JavaScript and work needed to update the screen. If it is busy with a long task, the code responding to a tap or the next visible update may have to wait.

For example, a menu button can already be visible while a script processes a large list; tapping it may open the menu only after that work finishes. This is one possible cause of a slow response. A feature that needs fresh server data can also make you wait for a network response.

[1] [7]
THE IDEA TO KEEP

Receiving files is part of loading; rendering turns their instructions into a view that can change.

ONE THING TO WATCH OUT FOR

Once text appears, the whole page must be finished.

More resources and later updates can still change the visible page.

A QUICK CHECK, NOT A TEST
A recipe title wraps onto another line when you narrow the window. What work does the browser need to do?
Show the explanation

Recalculate the affected sizes and positions. The available width changed, so the browser may need a new layout for the title and surrounding content.

Progress is saved only in this browser.

KEEP EXPLORINGHTTP
Was this explanation clear?
Report a mistake by email
Basic explanation
2 min read · estimate

YOUR GOALDistinguish the DOM, style calculation, layout, and the work that produces visible output.

Trace structure, style, and geometry.

Content and style are different inputs

Parsing HTML builds the Document Object Model (DOM): a tree representing the document. Parsed CSS is available through the CSS Object Model (CSSOM). The browser resolves applicable rules into computed styles.

The rendered structure is not a copy of every DOM node. For example, display: none removes an element and its subtree from layout while leaving the DOM intact. With visibility: hidden, an element can be invisible and still occupy space.

[2]

First find the boxes, then draw them

Layout, also called reflow, determines sizes and positions. For a paragraph, the browser needs to know where lines break and how much room they take.

Painting describes what to draw, rasterization produces pixels, and compositing combines rendered parts in the right order. For instance, a card's background must appear behind its text. These are useful stages for understanding rendering, not a promise that every browser uses identical internal structures.

[3]
THE IDEA TO KEEP

The DOM describes content; styles influence its appearance; layout determines geometry before the visible result is drawn.

ONE THING TO WATCH OUT FOR

Every DOM element must occupy a visible box.

Some nodes do not participate in layout, and an invisible element can still occupy space.

A QUICK CHECK, NOT A TEST
You want a notice to be invisible but keep its normal space in the page. Which choice fits?
Show the explanation

Use visibility: hidden on the notice. visibility: hidden can preserve the element's layout space. display: none and removing the element do not preserve its normal box.

Progress is saved only in this browser.

KEEP EXPLORINGHTTP
Was this explanation clear?
Report a mistake by email
Advanced explanation
3 min read · estimate

YOUR GOALReason about invalidation, synchronous measurements, and script scheduling without assuming every update redraws everything.

Identify which work an update actually triggers.

Different changes need different stages

Changing a card's width can require layout and repainting affected content. Changing only its text color generally needs paint without a new layout. Some updates to already composited layers can avoid both layout and paint.

The browser reuses work where possible. A diagram showing a pipeline does not mean every frame runs every stage. Check the actual page before assuming that a small CSS change is cheap or that putting everything on its own layer helps.

[5] [3]

Measure together, then update together

Writing a new width and immediately reading offsetHeight may force the browser to calculate current layout before returning the height. Repeating that write/read pattern across many cards can cause layout thrashing.

If you need the cards' existing heights, collect those measurements first, then make the width changes. If you need their heights after the change, old measurements are wrong: batch the changes and then collect the new measurements. A necessary measurement is not a bug; avoid needless repeated recalculations.

[6]

Downloading a script and running it are separate

A classic external script encountered in HTML without async or defer pauses parsing until it is fetched and executed. An external classic script with defer can download while parsing continues, then runs after parsing; deferred scripts preserve document order.

async also allows the download to overlap parsing, but execution starts when ready and can interrupt parsing. It does not guarantee order between scripts. For example, a script that needs an earlier library should not rely on two async tags executing in source order.

async changes when a script is fetched and executed; it does not remove its execution cost. Reducing unnecessary work or splitting a long task into smaller tasks with opportunities to yield can let the browser handle input and update the screen sooner.

[4] [7]
THE IDEA TO KEEP

Reduce unnecessary layout and repeated measurements, and choose script scheduling that matches the page's dependencies.

ONE THING TO WATCH OUT FOR

async means a script's execution can never delay the page.

Its download can overlap parsing, but executing it still uses time and can interrupt parsing.

A QUICK CHECK, NOT A TEST
You need the current heights of 40 cards before changing their widths. Which approach best avoids repeated write/read cycles?
Show the explanation

Read the existing heights together, then apply the width changes. The task needs the old geometry. Collecting it before the writes avoids repeatedly forcing calculations for changed geometry.

Progress is saved only in this browser.

KEEP EXPLORINGHTTP
Was this explanation clear?
Report a mistake by email
GO STRAIGHT TO THE SOURCE

Keep asking. Check the details.

Source-checked using AI (OpenAI Codex) on . The checks covered sources, examples, and quizzes for this article version.

No human review is claimed. AI review can miss errors; check the original sources below.

  1. MDN — Populating the page: how browsers work
  2. web.dev — Render-tree construction, layout, and paint
  3. Chrome for Developers — Inside look at modern web browser, part 3
  4. MDN — The script element, async, and defer
  5. web.dev — Rendering performance
  6. web.dev — Avoid large, complex layouts and layout thrashing
  7. web.dev — Optimize long tasks
How explanations are prepared