Critical CSS

On this page 7

Critical CSS is the minimal subset of style rules required to render the content visible in the first viewport of a page, delivered inline in the HTML document so the browser can paint without waiting for external stylesheets. In web performance, it is a technique for removing render-blocking CSS from the critical rendering path and improving metrics such as FCP and LCP.

The remaining, non-critical CSS is loaded asynchronously and applied after the first paint. The idea is simple, but a correct implementation requires careful extraction, size budgeting and a strategy for keeping the inlined rules synchronized with the full stylesheet.

Why stylesheets block the first paint

Browsers treat external stylesheets as render-blocking resources because painting unstyled content and then restyling it would cause a flash of unstyled content and costly relayout. Until every stylesheet linked in the head has been downloaded and parsed into the CSS Object Model (CSSOM), the browser cannot build the render tree and cannot paint.

On a fast connection the delay is small, but on mobile networks each stylesheet request can cost one or more round trips plus download time. A page that links a 150 KB framework stylesheet may wait hundreds of milliseconds after the HTML arrives before showing anything. Critical CSS shortens this wait by putting the styles needed for the above-the-fold content directly into a style element in the head, so the first paint depends only on the HTML response.

The following table shows how each stage of the rendering path is affected when critical styles are inlined.

Rendering stageFull external stylesheetCritical CSS inlined
HTML downloadRequiredRequired, slightly larger
Stylesheet requestBlocks renderingDeferred until after paint
CSSOM constructionWaits for full fileStarts from inline rules
First paintAfter stylesheet arrivesAfter HTML is parsed
Full stylingAt first paintWhen deferred file loads
Rendering stages with and without inlined critical styles

How critical CSS is extracted and delivered

Extraction tools render the page in a headless browser at one or more viewport sizes, record which elements appear inside the viewport, and keep only the selectors that match those elements. Popular build tools such as Critical, Penthouse and Critters automate this step, and some frameworks perform it during server-side rendering or static generation.

Delivery follows a standard pattern. The extracted rules go into a style element in the document head, and the full stylesheet is loaded without blocking, typically with a preload hint or with a link whose media attribute is switched to all after loading. A noscript fallback keeps the page styled when JavaScript is disabled.

  1. Render representative templates at mobile and desktop widths.
  2. Collect the selectors used by elements in the first viewport.
  3. Include required font-face and custom property declarations.
  4. Minify the result and inline it in the head.
  5. Load the complete stylesheet asynchronously and cache it.

The next table compares common extraction approaches and where each fits best.

ApproachHow it worksBest suited to
Build-time extractionHeadless rendering of templates during the buildStatic sites and stable templates
Runtime extractionServer computes rules per request or caches per routeHighly dynamic pages
Component-scoped CSSStyles emitted only for rendered componentsComponent frameworks with SSR
Manual curationDevelopers maintain a hand-written critical fileSmall sites with few layouts
Approaches to producing critical styles

Size budget and key parameters

The value of critical CSS depends on keeping the inlined block small. The guideline rests on TCP slow start: an initial congestion window of about 10 packets, roughly 14 KB compressed, can arrive in the first round trip. If the HTML together with the inline styles fits within that window, the browser can begin rendering after a single round trip from the server response.

With HTTP/2 and HTTP/3 the exact threshold matters less than in the past, but the principle remains: every inlined byte delays the HTML and is downloaded again on each page view because inline styles cannot be cached separately. Typical well-tuned critical blocks range from 5 KB to 20 KB uncompressed.

ParameterTypical value or choiceWhat it affects
Inline size5-20 KB uncompressedHTML transfer time and parse cost
Viewport sizesOne mobile and one desktop widthCoverage of above-the-fold layouts
Template coverageOne block per page typeAccuracy across different layouts
Fonts in scopePrimary text font onlyText rendering and layout shift
Regeneration triggerEvery build or deployDrift between inline and full CSS
Parameters that shape a critical CSS implementation

How critical CSS relates to neighboring techniques

Critical CSS is one of several techniques that address the critical rendering path, and it is often combined with them rather than used alone. It targets render-blocking styles specifically, while preload, minification and code splitting address other parts of the loading sequence.

TechniqueMain goalRelationship to critical CSS
PreloadFetch a resource earlierOften used to load the deferred stylesheet
MinificationReduce file sizeApplied to both inline and full CSS
Code splittingLoad only needed codeSimilar principle applied to JavaScript
Lazy loadingDefer offscreen mediaComplements deferred non-critical styles
Unused CSS removalDelete rules never usedShrinks the full file, not the first paint path
Comparison with related web performance techniques

The effect is measured mainly through First Contentful Paint and Largest Contentful Paint. A correct implementation should not worsen Cumulative Layout Shift; if it does, the critical block is missing rules that define dimensions or positions of visible elements.

Limitations and common mistakes

Critical CSS adds build complexity and a maintenance burden, and its benefits shrink when stylesheets are already small, cached or served from the same connection as the HTML. Sites with mostly returning visitors gain less, because a cached stylesheet no longer blocks rendering in a meaningful way.

SymptomLikely causeFix
Layout jumps after loadMissing dimension or grid rulesWiden extraction viewports, add rules
Flash of wrong stylesInline rules outdated after deployRegenerate on every build
Slower HTML deliveryInline block too largeTrim selectors, split per template
Unstyled page without JavaScriptNo noscript fallbackAdd a blocking link inside noscript
Duplicate style bytesRules repeated in both filesAccept or exclude inlined rules from full file
Typical problems and their remedies

A frequent misconception is that inlining all CSS is equivalent. Inlining a large stylesheet removes the extra request but inflates every HTML response and defeats caching, which usually harms repeat visits. Another mistake is extracting only at a desktop width, which leaves mobile layouts without the rules they need.

A non-technical view

Before a browser shows a page, it normally waits for the full design file that describes colors, fonts and layout. Critical CSS hands the browser a small excerpt of that file, covering only what appears on the screen first, so it can start drawing right away.

Think of a restaurant that brings bread and water the moment guests sit down, while the kitchen prepares the full meal. Visitors see something useful almost immediately, and the rest of the styling arrives quietly a moment later.

A concrete example

A news publisher serves article pages that link a 160 KB framework stylesheet. Field data shows a median First Contentful Paint of about 2.6 seconds on mobile, largely because the stylesheet blocks rendering on slower connections.

The front-end team adds a build step that renders the article template at 375 and 1280 pixels wide, extracts about 11 KB of critical rules, inlines them in the head and loads the full stylesheet asynchronously with a noscript fallback. The block is regenerated on every deploy.

After release, median mobile FCP drops to roughly 1.5 seconds and LCP improves by several hundred milliseconds, while layout shift stays unchanged. The outcome is a visibly faster first paint at the cost of a slightly larger HTML response.