Critical CSS: Extract, Minify and Inline for LCP

Critical CSS: Extract, Minify and Inline for LCP

Extract above-the-fold CSS, minify the block, inline it in the head, then load the rest async. How it helps LCP without shipping all styles first.

15.06.2026
10 min read
Share this article:
CSSCritical CSSLCPCore Web VitalsPerformanceOptimizationTutorial

Why CSS blocks your LCP

Every external stylesheet is render-blocking. The browser delays painting until it has downloaded and parsed the entire CSS file, even when only a handful of rules apply to above-the-fold content. On a landing page with 180 KB of styles, Largest Contentful Paint (LCP) can exceed 3 seconds on a slow mobile connection. The critical CSS strategy extracts the above-the-fold styles, minifies them, inlines them in the `<head>` and loads the rest asynchronously. To shrink the extracted block, the FastMinify online CSS minifier shows the savings. This guide covers the full workflow of extraction, minification, HTML inlining and measurement. It complements our complete CSS minification guide and the article on Core Web Vitals and minification.

LCP can improve on CSS-heavy pages; the gain depends on the page, the network and the size of the blocking CSS
Faster First Contentful Paint, because the above-the-fold content renders without waiting for the stylesheet
Elimination of render-blocking CSS resources for the first paint
A higher Lighthouse Performance score and a passing “Eliminate render-blocking resources” audit
Works well with CSS minification, Brotli compression and lean HTML

Impact on LCP

A marketing landing page before and after critical CSS

Illustrative numbers for a page with Bootstrap and a custom theme, as Lighthouse reports them on simulated mobile 4G. Your own results will differ:

Visual comparison of Lighthouse scores before and after Critical CSS optimization

Before optimization

LCP
3.8s
Google Score
62/100
File size
180 KB blocking CSS
Load time
2.1s FCP

After optimization

LCP
1.9s
Google Score
91/100
File size
4 KB inline + 176 KB async
Load time
0.9s FCP

Improvements

LCP: 3.8s → 1.9s (−50%)
Render-blocking CSS: 180 KB → 4 KB inline
Lighthouse Performance score: 62 → 91
FCP: 2.1s → 0.9s
« Eliminate render-blocking resources » audit: red to green
When to prioritize Critical CSS

The technique delivers the most value in these contexts:

Marketing / landing pages where the hero is the LCP element
WordPress or CMS themes with large monolithic CSS files
SSR or static sites without integrated CSS optimization pipelines
Mobile-first pages where LCP matters most
Projects targeting Google's LCP ≤ 2.5s threshold without a full rewrite

Measure impact on your Core Web Vitals

Validation tools

Verify that critical CSS improves field LCP as well as the synthetic Lighthouse score. Cross lab and field data:

Lighthouse in Chrome DevTools: the “Eliminate render-blocking resources” audit
PageSpeed Insights: LCP field data (CrUX) against lab data
WebPageTest: the filmstrip shows when the first paint happens
Chrome Performance panel: CSS parsing and rendering timeline
Search Console: Core Web Vitals report by URL group
Post-deployment target metrics

Compare before/after on a representative page sample. See our Core Web Vitals and fast-site SEO articles for Google thresholds and ranking impact.

LCP ≤ 2.5 s (good), the main goal of this optimization
Visible FCP drop on WebPageTest filmstrip
Fewer blocking CSS resources in Lighthouse
No CLS regression (hero/image dimensions still defined)
CrUX monitoring over 28 days to validate field LCP

Inline critical CSS in HTML

Preload with an asynchronous stylesheet

Combine inline CSS for the critical rules with deferred loading for the rest. This pattern works with most stacks. The noscript fallback keeps the page styled when JavaScript is off:

Place critical `<style>` as high as possible in `<head>`
Preload the full stylesheet to reduce async load latency
Provide a `<noscript>` fallback for visitors without JavaScript
Avoid inlining more than ~14 KB (historical HTML first-packet threshold)
Regenerate critical on every above-the-fold layout change

Before

<head> <link rel="stylesheet" href="/css/bundle.css"> </head> <body> <header class="hero">...</header> </body>

After

<head> <style>.hero{background:#0f172a;color:#fff;padding:2rem}</style> <link rel="preload" href="/css/bundle.css" as="style" onload="this.onload=null;this.rel='stylesheet'"> <noscript><link rel="stylesheet" href="/css/bundle.css"></noscript> </head>
Alternative: media="print" onload="this.media='all'" on the async link. Always test mobile rendering.

Integration in modern frameworks

Next.js

In Next.js 15, the experimental `optimizeCss` option inlines critical CSS with Critters, a package you install yourself. It only processes pages rendered by the Pages Router, so for App Router pages run `critical` on the built output:

Pages Router

In `next.config.js`, set `experimental: { optimizeCss: true }`. Critters then inlines the critical CSS of each Pages Router page in the HTML it serves.

Manual build

Run `critical` after the build on `out/index.html` (static export) or on snapshots of server-rendered pages.

Nuxt and Gatsby

Nuxt has a maintained module for this. For Gatsby, run `critical` after the build:

Nuxt

The `@nuxtjs/critters` module injects critical CSS into prerendered pages.

Gatsby

Run `critical` on the HTML files in `public/` after `gatsby build`.

Best practices and common pitfalls

Production checklist

Before you ship to production, check this list:

Critical CSS generated from production build, not dev
Extracted CSS minified before inline (CSSO or FastMinify)
Inline size ≤ 14 KB when possible. Beyond that, weigh the gain against the HTML size
Async CSS with noscript fallback tested
Automatic regeneration of the critical CSS in CI on layout CSS changes
Brotli compression enabled on async stylesheets, see the GZIP and Brotli guide
Common mistakes

These issues often appear after a first Critical CSS implementation:

FOUC (Flash of Unstyled Content): misconfigured async loading or incomplete critical CSS
Critical CSS too large: extraction dimensions set too tall, or rules from outside the viewport included
Stale critical CSS: the layout changed without regenerating the inline CSS
Ignored media queries: test mobile and desktop dimensions in critical or Penthouse
Forgotten web fonts: the LCP may be an image, or text affected by `font-display: swap`

What is Critical CSS?

Above-the-fold and render-blocking

Critical CSS is the minimal set of rules needed to display above-the-fold content correctly in the initial viewport: header, hero, base typography, main layout. Every external `<link rel="stylesheet">` blocks rendering while the browser builds the CSSOM. Minification reduces size; Critical CSS reduces blocking by delivering those rules inline without a network round trip.

Critical CSS = first-viewport styles, not the entire stylesheet
Render-blocking: external CSS delays FCP and LCP
Minification and Critical CSS are complementary, not substitutes
Non-critical CSS loads async afterward (preload, media print trick)
Goal: paint fast, then enrich styles without blocking
Typical before and after pattern

The most common transformation on a static or SSR page:

Before

<head> <link rel="stylesheet" href="/styles/main.css"> <!-- 180 KB blocking before first paint --> </head>

After

<head> <style>/* ~4 KB minified critical CSS inline */</style> <link rel="preload" href="/styles/main.css" as="style" onload="this.onload=null;this.rel='stylesheet'"> <noscript><link rel="stylesheet" href="/styles/main.css"></noscript> </head>

Minify your Critical CSS with FastMinify

Extract, minify, inline

After extraction with `critical` or Penthouse, paste the CSS into FastMinify's online CSS minifier to get the most compact version before inlining. If you serve static pages, minify the final HTML with our online HTML minifier as well.

Critical CSS flow diagram: extraction, minification, inline and async loading
1

1. Extract

Generate `critical.css` with critical or Penthouse on your production build, not on the dev build, because class names may differ.

2

2. Minify

Paste the extracted CSS into FastMinify and compare the size before and after. Aim for under 14 KB inline when possible.

3

3. Inline it and defer the rest

Insert the minified CSS in a `<style>` tag in the `<head>`. Load the full stylesheet asynchronously with preload or the `media="print"` trick.

Extract critical CSS programmatically

The critical package (Node.js)

The `critical` package is the standard way to generate critical CSS from a URL or HTML file. Configure viewport dimensions (mobile + desktop) to cover real-world cases:

Configuration

const critical = require('critical'); critical.generate({ inline: true, base: 'dist/', src: 'index.html', target: 'index-critical.html', width: 1300, height: 900, dimensions: [ { width: 375, height: 667 }, { width: 1300, height: 900 } ] });

Usage

// Penthouse (alternative) — similar API const penthouse = require('penthouse'); const criticalCss = await penthouse({ url: 'https://example.com', css: 'dist/styles/main.css', width: 1300, height: 900 });
Minify extracted CSS before inlining

Generated CSS still contains whitespace and comments. Run it through CSSO or our online tool before inlining. The CSS minification guide covers advanced options. Savings are often 20–40% on the extracted block, the range our CSS tool documentation gives.

Configuration

const csso = require('csso'); const fs = require('fs'); const raw = fs.readFileSync('critical.css', 'utf8'); const minified = csso.minify(raw, { restructure: true }).css; fs.writeFileSync('critical.min.css', minified);

Usage

// Or via FastMinify: paste extracted CSS, // minify, copy result into <style>...</style>

Conclusion

Critical CSS can improve LCP without rewriting your stack. Extract the above-the-fold styles, minify them, inline them in the HTML and defer the rest. Combine it with systematic CSS minification, Brotli compression and lean HTML.

Minify your critical CSS now

Extract critical CSS with critical or Penthouse at build time
Minify the extracted block before inline with FastMinify or CSSO
Inline it in the head and load the rest asynchronously
Measure LCP before/after with Lighthouse and PageSpeed Insights
Automate regeneration in CI to avoid stale critical CSS
Share this article
Share this article: