Critical rendering path

On this page 7

The critical rendering path is the sequence of steps a browser performs to turn HTML, CSS and JavaScript into pixels on the screen for the first time: parsing markup into the DOM, parsing styles into the CSSOM, combining them into a render tree, calculating layout and painting. Among browser technologies it is the central model for understanding why a page appears quickly or slowly.

The word critical refers to the resources and work that block the first render. Anything on this path delays what the visitor sees, while resources off the path can load later without holding up the screen. Optimizing the critical rendering path means shortening, shrinking and reordering that blocking work.

The stages of the critical rendering path

The rendering engine processes a page in a pipeline. Some stages run incrementally as bytes arrive, but the first paint cannot happen until the render tree for visible content exists, which requires both the DOM and the complete CSSOM.

StageInputOutput
HTML parsingHTML bytesDOM tree, built incrementally
CSS parsingAll render-blocking stylesheetsCSSOM tree
Script executionParser-blocking scriptsPossible DOM and CSSOM changes
Render tree constructionDOM and CSSOMTree of visible nodes with computed styles
LayoutRender tree and viewport sizeExact position and size of each box
PaintLayout resultDrawing commands for pixels in layers
CompositingPainted layersFinal frame on the screen
Stages of the critical rendering path

The render tree contains only visible content: elements styled with display: none are excluded, while elements with visibility: hidden still occupy layout space. Layout, sometimes called reflow, depends on the viewport, which is why the viewport meta tag influences the first layout on mobile devices.

Render-blocking and parser-blocking resources

Two kinds of blocking shape the path. Render-blocking resources prevent painting until they are processed; by default every stylesheet in the document head is render-blocking, because painting without styles would cause a flash of unstyled content. Parser-blocking resources stop HTML parsing itself; a classic script without attributes pauses the parser until it has downloaded and executed.

Scripts are also delayed by CSS: a classic script waits for preceding stylesheets to load, because it might read computed styles. A slow stylesheet therefore blocks both the paint and any script that follows it.

Resource and optionBlocks parsingBlocks renderingExecution timing
Stylesheet in headNoYesApplied before first paint
Stylesheet with non-matching mediaNoNoApplied when the media matches
Classic scriptYesIndirectlyImmediately, in order
Script with deferNoNoAfter parsing, in document order
Script with asyncNoNoAs soon as loaded, any order
Module scriptNoNoDeferred by default
How resource loading options affect blocking

Metrics that describe the critical rendering path

The path can be described by three practical quantities: the number of critical resources, the total critical bytes and the critical path length, meaning the number of sequential network round trips required before the first render. Each additional round trip adds at least one network latency, which on mobile connections commonly amounts to tens to hundreds of milliseconds.

User-facing metrics reflect the path’s outcome. First Contentful Paint marks the first text or image drawn, and Largest Contentful Paint, one of the Core Web Vitals, marks when the largest visible element appears; a value of 2.5 seconds or less at the 75th percentile is considered good.

MeasureWhat it capturesDirection of improvement
Critical resourcesFiles that block first renderFewer
Critical bytesSize of those files after compressionSmaller
Critical path lengthSequential round trips before renderShorter
First Contentful PaintFirst visible contentEarlier
Largest Contentful PaintMain content visibleEarlier, ideally within 2.5 s
Quantities and metrics related to the critical rendering path

Optimizing the critical rendering path

Optimization follows three principles: remove work from the path, make remaining work smaller, and start critical downloads earlier. The table maps common problems to established techniques.

ProblemTechniqueEffect
Large blocking stylesheetInline critical CSS, load the rest laterFirst paint needs no extra round trip
Blocking scripts in headUse defer or module scriptsParser no longer waits
Late-discovered fonts or hero imagePreload with high priorityDownload starts earlier
Third-party origin delayPreconnect to the originConnection setup happens in advance
Large HTML or CSS filesCompression and minificationFewer critical bytes
Invisible text while fonts loadUse font-display: swapText appears with a fallback font
Techniques for shortening the critical rendering path

Inlining critical CSS works best when it stays small, roughly within the first 14 KB of compressed HTML that typically arrives in the initial round trip of a new connection. Inlining too much enlarges every HTML response and bypasses browser caching of the stylesheet.

Common misconceptions and pitfalls

Critical rendering path work is easy to get partly right. The following misconceptions cause wasted effort or regressions.

  • Async solves everything: async scripts run in unpredictable order and can still interrupt parsing when they execute.
  • Preloading many files: preloading competes for bandwidth; preload only truly critical resources.
  • Ignoring the server: a slow time to first byte delays the entire path before parsing even begins.
  • Client-rendered first view: a page that renders content only after a large bundle executes puts JavaScript on the critical path.
  • Testing on fast hardware only: desktop tests on fiber hide the latency of mobile networks.

The idea in brief

The critical rendering path is the list of jobs a browser must finish before showing a page. It reads the page text, reads the styling rules, works out where everything goes and then draws it. Some files must arrive before drawing can start.

Think of preparing a dish where some ingredients are essential. Until those arrive, nothing can be served. Speeding up a page mostly means making the essential list shorter and getting those items delivered first.

A practical scenario

A travel company’s landing page shows its main headline only after about 4 seconds on mid-range phones. A performance audit finds three blocking stylesheets totaling 180 KB, two classic scripts in the document head, and a custom web font that hides text until it loads.

The team inlines about 10 KB of critical CSS for the visible area and loads the remaining styles without blocking. Both scripts receive the defer attribute, the hero image is preloaded with high priority, the font uses font-display: swap, and a preconnect is added for the image host. The critical path drops from four round trips to one for the first render.

Field data over the following month shows Largest Contentful Paint at the 75th percentile falling to about 2.2 seconds, inside the good threshold, and visitors see the headline almost immediately.