In this guide
You type a URL, press Enter, and a page appears. Between those two moments the browser does an astonishing amount of work: it fetches files, parses two languages, builds three trees, calculates the position of every element, paints pixels, and then keeps doing it — sixty times a second — every time you scroll or tap. Most of that work is invisible, which is why most web developers never learn how it happens, and why their pages are slower than they need to be.
This guide walks through the browser's rendering pipeline, step by step, in the order it actually happens — from the first byte of HTML to the pixels on your screen — and shows you where to look when a page feels slow.
Quick answer
The browser turns HTML into a DOM tree and CSS into a CSSOM tree, combines them into a render tree of only the visible elements, calculates each element's size and position in a step called layout, paints the result into layers, and composites those layers into the final image.
The pipeline at a glance
Before the details, the shape of the whole process:
- Navigation and fetching — the browser resolves the URL, downloads the HTML, and starts downloading CSS, JavaScript, fonts, and images as it discovers them.
- Parsing HTML into the DOM — the HTML is read token by token and built into the Document Object Model, a tree of elements.
- Parsing CSS into the CSSOM — stylesheets are parsed into the CSS Object Model, a tree of style rules.
- Building the render tree — DOM and CSSOM combine into a tree containing only elements that will actually be displayed.
- Layout — the browser calculates the exact size and position of every visible element.
- Paint — elements are drawn into layers: text, colours, borders, shadows, images.
- Compositing — layers are combined into the final image on screen.
Steps 5 to 7 repeat whenever something changes — a window resize, a class change, an animation — which is why understanding them matters for performance, not just for curiosity.
Step 1: Navigation and fetching
Rendering starts before a single byte of HTML arrives. The browser looks up the domain, opens a connection, and requests the page. The server's response headers matter here: a slow server delays everything downstream, and the Content-Type header tells the browser how to interpret the response.
As the HTML streams in, the browser does not wait for the whole file. It starts parsing immediately and, while parsing, it scans ahead for resources — stylesheets, scripts, images — and starts downloading them in parallel. This lookahead scanner is why a page with many images does not download them one at a time.
Two resources can stall the whole pipeline at this stage. A stylesheet in the document head blocks rendering until it is downloaded and parsed, because the browser refuses to paint a page it may have to repaint. A synchronous script in the head blocks parsing until it is downloaded and executed. That is why the standard advice — stylesheets in the head, scripts at the end of the body or marked to load without blocking — exists: it is not a style preference, it is a description of this pipeline.
Step 2: HTML parsing and the DOM
The browser reads the HTML stream and builds the DOM — a tree where each element, attribute, and piece of text is a node. The parser is forgiving: unclosed tags get closed, misplaced elements get moved, and the browser builds a valid tree even from sloppy markup. That forgiveness is why a page with broken HTML still renders — and why the rendered result sometimes differs from what the author intended.
The DOM is also a live structure. JavaScript can add, remove, and modify nodes at any time, and every change can trigger the later pipeline stages again. This is the first of several reasons that heavy DOM manipulation feels slow: the browser is not just changing data, it is re-running parts of the render.
One detail students often miss: the DOM is not the HTML. The HTML is the text file the server sent; the DOM is the tree the browser built from it, after fixing errors and after scripts have modified it. When you inspect a page in developer tools, you are looking at the DOM, not the original file.
Step 3: CSS parsing and the CSSOM
While the DOM is being built, stylesheets are parsed into the CSSOM — a tree of style rules, organised by selector, with each rule's declarations attached. Unlike the DOM, the CSSOM cannot be built incrementally in the same way: the browser needs the complete stylesheet before it can be sure which rules apply, because a rule later in the file can override an earlier one.
This is the reason CSS blocks rendering. The browser will not paint until the CSSOM is ready, because painting with incomplete styles would mean painting twice — once wrong, once right. The practical consequence is direct: a large stylesheet, or a stylesheet served slowly, delays the first paint of the entire page, no matter how small the HTML is.
CSS also has its own performance cost. Browsers match selectors right to left, so a deeply nested selector forces the browser to check more ancestors for every element. The cost is small per element and large across a page of thousands of nodes, which is why keeping selectors short and flat is genuine performance advice, not just code tidiness.
Step 4: The render tree
The render tree is the combination of DOM and CSSOM, and it contains only what will be displayed. Elements with display: none are left out entirely — they take up no space and cost no layout. Elements with visibility: hidden stay in the tree (they occupy space) but produce no paint output. Pseudo-elements such as ::before appear as nodes in the render tree even though they do not exist in the DOM.
This step is cheap compared with what follows, but it is where the browser first knows what the page actually looks like as a visual structure — which elements exist, in what order, with which computed styles.
Step 5: Layout — geometry
Layout, also called reflow, is where the browser calculates the size and position of every node in the render tree. It starts at the root and works down: the viewport gives the root its width, each element's width, height, margins, padding, and position are computed from its styles and its parent's geometry, and children are placed inside their parents.
Layout is the most expensive stage of the pipeline, and its cost grows with the size of the tree. Worse, layout is often cascading: changing the width of one element can change the layout of its siblings, its parent, and everything below it. Reading a layout property from JavaScript — such as an element's height — immediately after changing a style forces the browser to run layout synchronously to give you an up-to-date answer. Doing that in a loop, alternating writes and reads, is called layout thrashing, and it is one of the most common causes of janky pages: the browser runs the most expensive step once per iteration instead of once per frame.
The practical rule follows directly: batch your style writes together, read layout properties separately, and never interleave them in a loop.
Step 6: Paint — pixels
Painting fills in the visual details: text, colours, backgrounds, borders, shadows, images. The browser paints into layers rather than one flat image, so that parts of the page that move independently — a fixed header, an animated element — can be repainted without repainting everything else.
Some CSS properties are cheap to change at this stage and some are not. Changing a colour or a background triggers a repaint of the affected layer. Changing an element's size or position triggers layout first, then paint. Animating transform and opacity is special: in most cases the browser can skip both layout and paint and go straight to compositing, which is why those two properties are the recommended choice for animations.
Step 7: Compositing — the final image
Compositing takes the painted layers and combines them into the single image shown on screen, using the GPU where possible. Layers are ordered by stacking context — the rules that decide which element appears on top when they overlap — and each layer is drawn in its correct place, with transforms and opacity applied.
Compositing is fast, which is the whole point of the layer system: scrolling a page mostly moves existing layers around rather than repainting them. But layers are not free. Every layer consumes GPU memory, and a page that creates hundreds of layers — for example, by promoting every element with a 3D transform — can run out of memory on a low-end phone and get slower, not faster.
Putting it together: the critical rendering path
The critical rendering path is the sequence of steps between the first byte and the first paint, and it is the single most useful concept for page speed. Everything on that path delays the moment the user sees something; everything off it does not.
The path is, in order: download the HTML, download and parse the CSS, download and execute any parser-blocking scripts, build the DOM and CSSOM, build the render tree, run layout, paint, composite. Images, fonts, and scripts marked to load without blocking sit outside this path — they can arrive late without delaying the first paint, though they can still cause visible shifts when they finally load.
Three optimisations follow from the path itself, and they explain most of the standard performance advice:
- Minimise render-blocking CSS. Keep the stylesheet small, and load non-critical CSS after the first paint.
- Defer non-critical JavaScript. Scripts that are not needed for the first paint should load without blocking parsing.
- Inline the critical CSS. A small amount of CSS in the document head lets the browser paint before the full stylesheet arrives.
How to watch the pipeline yourself
You do not need to take any of this on trust. Open any page in Chrome or Firefox, open developer tools, and:
- Network panel — shows every resource, its size, and how long it took. Look for the stylesheet and scripts that finish before the first paint.
- Performance panel — record a page load and you will see the pipeline as a timeline: parsing, style calculation, layout, paint, and compositing, each labelled with how long it took.
- Rendering drawer — paint flashing highlights the parts of the page being repainted in real time. Scroll a page and watch: a good page repaints almost nothing; a bad one flashes everywhere.
- Elements panel — the DOM as the browser sees it, with computed styles. Compare it with the raw HTML source to see what the parser fixed and what scripts changed.
Run these tools on your own project pages. A page that paints in under a second with a clean Performance timeline is the goal; a page whose timeline is dominated by repeated layout is telling you exactly what to fix.
Frequently asked questions
Why does my page show unstyled content for a moment?
The browser painted before the stylesheet arrived — a flash of unstyled content. It usually means the CSS is large, slow to download, or loaded late. Move the stylesheet link into the head and reduce its size.
Do images block rendering?
No. Images are fetched in parallel and painted when they arrive. But an image without width and height attributes can push content around when it loads, causing a visible shift — always reserve the space in advance.
What is the difference between reflow and repaint?
Reflow (layout) recalculates geometry — sizes and positions. Repaint redraws pixels without changing geometry. Reflow is more expensive and usually triggers a repaint as well; a repaint alone happens when only colours or visibility change.
Why are transform and opacity recommended for animations?
Because they can be handled at the compositing stage without re-running layout or paint. Animating width, height, top, or left forces layout on every frame, which is why those animations often look choppy.
Does the browser re-run the whole pipeline on every change?
No — only the stages the change requires. Changing text content triggers layout and paint for the affected elements; changing a colour triggers paint only; changing a transform usually triggers compositing only. The browser is efficient about this, but a change at the top of the tree can still cascade widely.
Limitations
This guide describes the standard pipeline shared by Chrome, Firefox, and Safari, but the implementations differ in details: each engine has its own parser, its own compositing strategy, and its own thresholds for when layers are created. Exact timings also vary enormously by device — a pipeline that feels instant on a desktop can be slow on a budget phone with a weak CPU and GPU. The concepts and the debugging tools transfer; the numbers do not.