Skip to content

Search

Articles, tools, solutions and knowledge base guides

Start typing to search across articles, tools and apps.

Critical Rendering Path: how the browser renders a page and how to optimize it

The Critical Rendering Path describes the route from receiving HTML to displaying pixels on the screen. It is one of the most useful mental models in frontend performance because it explains why a small stylesheet can delay first render, why a plain script in <head> can stop the parser, and why late discovery of a critical resource can hurt LCP even when the file itself is small. This guide walks through DOM, CSSOM, render tree, layout, paint and compositing, then shows how to shorten the critical path without creating new bottlenecks.

Published Written by Reading time 25 min read
On this page Contents: quick navigation between sections

What the Critical Rendering Path really is

StageWhat happensTypical bottleneck
HTML parsingDOMParser-blocking script
CSS parsingCSSOMRender-blocking stylesheet
Style + DOMRender treeLarge style calculation scope
LayoutGeometryLarge DOM, repeated reflow
Paint / compositingPixels and layersLarge repaint or expensive effects

MDN defines the Critical Rendering Path as the sequence of steps a browser uses to convert HTML, CSS and JavaScript into pixels. The core model includes the DOM, CSSOM, render tree, layout and paint. [1]

It is not a single metric or a single phase. CRP is a dependency model: what must be fetched, parsed and calculated before content can be shown.

It is also useful to separate first-render performance from later updates. A page can appear quickly yet still suffer from expensive layout, paint or JavaScript work during interaction.

From the HTML response to the DOM

After HTML arrives, the browser tokenizes the document and builds the DOM. MDN notes that DOM construction is incremental, allowing the parser to discover elements and resources before the whole document has downloaded. [1][2]

A high node count is not automatically a bug, but a very large DOM can increase the cost of later style and layout work. Optimize from measurements rather than an arbitrary element-count rule. [1]

For initial rendering, content near the top of the document and the dependencies discovered during parsing are especially important.

The preload scanner tries to get ahead of the parser

Modern browsers use an additional scanner that looks for references to resources such as CSS, scripts and images while the main parser is busy. This allows some requests to start earlier. [2]

The preload scanner cannot solve every dependency. Resources hidden behind JavaScript or revealed only after another file is processed may still be discovered late.

Critical resources should therefore be declaratively visible in HTML whenever practical. That is usually a stronger starting point than compensating later with many manual preloads.

CSSOM and render-blocking CSS

Critical and conditional stylesheets

<link rel="stylesheet" href="/en/css/main.css">

<link
  rel="stylesheet"
  href="/en/css/print.css"
  media="print"
>

<link
  rel="stylesheet"
  href="/en/css/narrow.css"
  media="screen and (width <= 480px)"
>

CSS determines how elements should be rendered. MDN describes CSS as render-blocking because the browser needs style information before it can correctly build the render tree and paint. [1][3]

An external <link rel="stylesheet"> in <head> is render-blocking by default. This does not mean every stylesheet should be inlined, but it makes the size and number of critical stylesheets important. [3]

Stylesheets that apply only under other conditions, such as media="print", can still download without blocking rendering for the current screen. [3]

DOM + CSSOM -> render tree

Once DOM and style information are available, the browser can build a render tree representing content that needs to be rendered together with computed styles. Elements hidden with display: none and their descendants are not represented in the render tree. [1]

The render tree is therefore not a direct copy of the DOM. Its purpose is to represent what actually needs layout and paint.

Optimizing DOM size without understanding styles and visibility can produce misleading conclusions. Measure the whole rendering pipeline.

Layout calculates geometry

During layout the browser determines element sizes and positions from the viewport, box model and relationships between elements. Resizing the viewport or changing geometry-affecting content and styles may require layout again. [1]

A large complex DOM can increase layout cost, especially when geometry calculations are repeatedly triggered during animation, scrolling or interactions. [1]

Layout itself is not an error. It is a normal rendering phase. The performance problem is excessive scope, frequency or forced timing.

Paint and compositing turn geometry into pixels

After geometry is known, the browser paints content. On subsequent updates, browsers generally repaint only affected regions, though complex styles and large areas can increase paint cost. [1]

Chrome DevTools provides Paint Flashing to show repainted areas and Layer Borders to inspect rendering layers. [14]

For animation, prefer approaches that avoid repeated layout and large repaint areas, but verify the actual bottleneck with a profile rather than assuming a CSS property is expensive.

JavaScript: parser blocking, defer, async and modules

Classic script, defer, async and module

<!-- Parser-blocking classic script -->
<script src="/js/legacy.js"></script>

<!-- Fetches in parallel, executes after HTML parsing -->
<script src="/js/app.js" defer></script>

<!-- Fetches in parallel, executes as soon as available -->
<script src="/js/analytics.js" async></script>

<!-- Module scripts are deferred by default unless async is used -->
<script type="module" src="/js/app.mjs"></script>

Under the HTML Standard, a classic external <script> without async or defer blocks further parsing while it is fetched and evaluated. defer fetches in parallel and evaluates after parsing; async evaluates as soon as the script is ready. [4]

Module scripts without async are deferred by default. Adding async allows the module graph to evaluate as soon as it is ready and removes ordering guarantees relative to other scripts. [4]

Application code that depends on the DOM usually fits defer or modules, while async is more suitable for independent code such as some analytics scripts.

Current MDN and Chrome guidance follows the same general rule: defer noncritical JavaScript and reduce or split main-thread work instead of executing everything before first render. [7][8]

Critical CSS: reduce blocking without creating a fragile hack

A small set of styles required for the first viewport can be inlined to avoid an extra request before first render. MDN lists critical CSS as a perceived-performance technique. [3]

Do not inline the entire application stylesheet. Large inline CSS increases HTML size, reduces cache reuse and can duplicate bytes across pages.

Use media conditions for styles not required in the current context, and be careful with dependency chains that delay discovering additional styles.

preload and modulepreload: fix discovery only where needed

Preloading a font and module

<link
  rel="preload"
  href="/en/fonts/brand.woff2"
  as="font"
  type="font/woff2"
  crossorigin
>

<link
  rel="modulepreload"
  href="/en/js/dashboard.mjs"
>

rel="preload" declares a resource needed very early so its request can begin sooner. Preload itself does not execute a script; it fetches and caches the resource according to request parameters. [5]

rel="modulepreload" is designed for JavaScript modules. MDN notes that modules can be fetched, parsed, compiled and placed into the document's module map ahead of later evaluation. [6]

Do not preload everything. Excessive preloads compete for bandwidth with truly critical resources and can make performance worse. [5][6]

Critical Rendering Path and LCP

LCP is not the same thing as the Critical Rendering Path, but the two are closely connected. An LCP element cannot be presented while the browser is still waiting for resources or rendering prerequisites.

Chrome DevTools breaks LCP into TTFB, resource load delay, resource load time and element render delay. Render-blocking CSS, late resource discovery and heavy main-thread work can increase different parts of this timeline. [13]

For that reason, optimizing LCP should not stop at compressing the hero image. Inspect what actually delays rendering and when the critical resource was discovered.

content-visibility: skip work for large offscreen sections

Skipping rendering work for offscreen sections

.section-below-fold {
  content-visibility: auto;
  contain-intrinsic-size: auto 800px;
}

content-visibility: auto allows the browser to skip some layout and paint work for offscreen content until it becomes needed. MDN marks the feature as broadly available across current browsers since 2024. [9]

On long pages or complex views this can reduce initial rendering cost. contain-intrinsic-size can provide an estimated size to reduce layout shifts when skipped content becomes rendered. [9]

It is not always a replacement for pagination, virtualization or a simpler DOM. Use it where profiling shows meaningful offscreen rendering cost.

Runtime rendering: avoid interleaving layout reads and writes

Batching DOM reads and writes

// Avoid interleaving DOM reads and writes.
const cards = [...document.querySelectorAll(".card")];

// Read phase
const widths = cards.map((card) => card.getBoundingClientRect().width);

// Write phase
requestAnimationFrame(() => {
  cards.forEach((card, index) => {
    card.style.setProperty("--measured-width", `${widths[index]}px`);
  });
});

After load, JavaScript can trigger additional style recalculation and layout. A particularly expensive pattern is repeatedly mixing geometry reads with DOM writes that invalidate layout.

In practice, batch reads and then batch writes. requestAnimationFrame() schedules a callback before the next repaint and is the right primitive for coordinating visual updates with the rendering cycle. [10]

MDN also advises against layout-affecting DOM changes from idle callbacks, since they can force recalculation after a frame's rendering work has already completed. [11]

Diagnosing the CRP in Chrome DevTools

What to inspectWhereWhat to look for
Render-blocking requestPerformance / Network trackMarker, initiator, priority
Main threadPerformanceLong scripting, style, layout, paint
RepaintRendering -> Paint FlashingUnexpectedly large repaint regions
Layout shiftRendering / PerformanceWhich element moved and when
LCPPerformance InsightsResource delay, load time, render delay

The Performance panel can record page-load profiles, apply CPU and network throttling, and expose main-thread activity, requests, style, layout and paint. [12]

Render-blocking requests are marked in the Network track, and request details expose initiators plus initial and final priority. This helps distinguish slow transfer from late discovery and dependency ordering. [13]

The Rendering tab adds Paint Flashing, Layout Shift Regions, Layer Borders and frame-rendering statistics for visual confirmation of paint and layout behavior. [14]

Practical Critical Rendering Path checklist

Example: blocking head and a simpler alternative

<head>
  <link rel="stylesheet" href="/en/css/all.css">
  <script src="/js/vendor.js"></script>
  <script src="/js/app.js"></script>
</head>

<!-- Better -->
<head>
  <meta name="viewport" content="width=device-width, initial-scale=1">

  <link rel="stylesheet" href="/en/css/critical.css">
  <link rel="stylesheet" href="/en/css/print.css" media="print">

  <script src="/js/app.js" defer></script>
</head>

First remove resources that should not be on the critical path at all. Only then tune priorities, preloads and CSS partitioning. Fewer critical dependencies mean fewer places where the browser can wait.

Do not apply one optimization template to every page. A content site, application dashboard and marketing landing page have different critical resources. Let DevTools show what blocks the actual view.

  • Remove unused CSS and JavaScript from the initial path.
  • Choose defer or async deliberately for classic scripts.
  • Remember that modules without async are deferred by default.
  • Keep CSS that truly blocks first render as small as practical.
  • Scope styles that are irrelevant to the current medium.
  • Use preload and modulepreload only for measurably critical resources.
  • Consider content-visibility: auto for heavy offscreen sections on long pages.
  • Profile again after every change, including with CPU and network throttling.

The Critical Rendering Path is valuable because it connects networking, HTML parsing, CSS, JavaScript and rendering into one model. The largest wins usually come from removing unnecessary critical resources, improving discovery order, deferring noncritical JavaScript, reducing render-blocking CSS and limiting later layout and paint work. The central rule is to measure the actual critical dependency chain first and optimize the places where the browser is truly waiting.

Critical Rendering Path Web Performance DOM CSSOM Render Tree Layout Paint Render Blocking JavaScript Performance CSS Performance Preload modulepreload LCP Chrome DevTools

Frequently asked questions

What is the Critical Rendering Path?

It is the sequence used to turn HTML, CSS and JavaScript into a rendered page, including DOM, CSSOM, render tree, layout and paint. [1]

Does CSS always block rendering?

A rel="stylesheet" in <head> is render-blocking by default, while styles scoped to nonmatching media do not need to block the current view. [3]

Does JavaScript always block the HTML parser?

No. A classic external script without async or defer blocks parsing, while those attributes change behavior and module scripts are deferred by default. [4]

What is the difference between async and defer?

async evaluates as soon as the script is ready without ordering guarantees. defer waits until document parsing has completed. [4]

Does type="module" need defer?

No. Module scripts without async are deferred by default and the defer attribute has no effect on them. [4]

Should all CSS be inlined?

Usually no. Small critical CSS can help first render, but large inline CSS increases HTML size and reduces cache reuse. [3]

When should preload be used?

When a high-value resource is needed early but normal discovery finds it too late. Use measurements to justify it. [5]

How is modulepreload different from JavaScript preload?

modulepreload is designed for modules and can fetch, parse and compile them into the module map before execution. [6]

Are complex CSS selectors the main performance problem?

Usually not. MDN notes selector cost is often small relative to larger bottlenecks, so measure before optimizing it. [1][3]

What does content-visibility: auto do?

It lets the browser skip some rendering work, including layout and paint, for offscreen content until needed. [9]

How do I find render-blocking requests?

Chrome Performance marks render-blocking requests and exposes initiators and priorities in the Network track. [13]

Is the CRP only about initial page load?

It primarily explains the route to rendering, but understanding layout and paint also helps diagnose later updates and jank. [1][14]

Sources and references

  1. MDN, Critical rendering path↩1↩2↩3↩4↩5↩6↩7↩8↩9↩10↩11
  2. MDN, Populating the page: how browsers work↩1↩2
  3. MDN, CSS performance optimization↩1↩2↩3↩4↩5↩6↩7
  4. WHATWG HTML Standard, script element↩1↩2↩3↩4↩5
  5. MDN, rel=preload↩1↩2↩3
  6. MDN, rel=modulepreload↩1↩2↩3
  7. MDN, JavaScript performance optimization↩
  8. Chrome for Developers, Modern Web Guidance: Performance↩
  9. MDN, content-visibility↩1↩2↩3
  10. MDN, requestAnimationFrame()↩
  11. MDN, Background Tasks API↩
  12. Chrome DevTools, Performance panel↩
  13. Chrome DevTools, Performance features reference↩1↩2↩3
  14. Chrome DevTools, Rendering performance↩1↩2↩3

Was this helpful?

Get new articles by email

One short email per new Learning article. No spam, unsubscribe in one click.

We only use your email to send new articles. No third-party sharing.

Back to Learning