CSS Critical Path Extractor
Identify above-the-fold CSS, extract critical styles for inlining, and detect unused rules. Optimize your page's render-blocking resources for faster First Contentful Paint. Client-side only.
HTML Source
CSS Source
Viewport Size
Understanding the Critical Rendering Path
The critical rendering path is the sequence of steps the browser takes to convert HTML, CSS, and JavaScript into pixels on screen. CSS is render-blocking by default: the browser will not paint any content until it has downloaded, parsed, and constructed the CSSOM (CSS Object Model) from all linked stylesheets. For a page with a 150KB external stylesheet on a 3G connection, this means the user sees a blank white screen for 2-4 seconds while the CSS downloads, even if the HTML arrived instantly.
Critical CSS optimization breaks this bottleneck by splitting your styles into two categories. First, the critical CSS: the minimal set of rules needed to render what the user sees first (above the fold). This CSS is inlined directly in the HTML document's head tag, eliminating the need for an additional network request. Second, the deferred CSS: everything else, loaded asynchronously after the initial paint. The result is a dramatically faster First Contentful Paint (FCP), often improving by 1-3 seconds on slower connections.
How This Tool Works
This extractor analyzes your HTML and CSS to classify every CSS rule into one of three categories. Critical rules match elements present in your above-the-fold HTML and are essential for the initial render. Deferred rules are valid CSS that targets elements not present in the provided HTML — these are styles for below-the-fold content, modals, dropdowns, and other interactive states. Unused rules do not match any element in your full page and may be dead CSS that can be removed entirely.
The tool parses your CSS into individual rules, extracts the selectors, and tests each selector against your HTML DOM. For media queries, it checks whether the query matches the selected viewport width. Rules inside matching media queries are classified by their selector; rules inside non-matching media queries are automatically classified as deferred. Pseudo-elements and pseudo-classes are handled by testing the base selector (e.g., .btn:hover checks if .btn exists in the HTML).
The 14KB Rule
TCP connections use a mechanism called slow start, where the initial congestion window (initcwnd) is typically 10 TCP segments, or approximately 14KB after compression. This means the first 14KB of data arrives in a single network round-trip. Any data beyond 14KB requires additional round-trips, each adding one RTT (Round-Trip Time) of latency. On a typical 4G connection with 50ms RTT, exceeding 14KB adds 50ms per additional round-trip.
This makes 14KB the golden budget for your combined HTML plus inline critical CSS. If your HTML document with inlined critical CSS fits within 14KB (gzipped), the browser receives everything it needs to paint the above-the-fold content in a single round-trip. This is the theoretical minimum time to first paint. Achieving this requires aggressive critical CSS minimization: remove whitespace, combine shorthand properties, eliminate redundant selectors, and question whether every above-the-fold style is truly necessary.
Implementing Critical CSS
The Inline + Async Pattern
The standard implementation pattern has three parts. First, inline your critical CSS in a <style> tag in the document head. Second, load your full stylesheet asynchronously using the media-swap technique: <link rel="stylesheet" href="style.css" media="print" onload="this.media='all'">. Third, add a <noscript> fallback for users without JavaScript: <noscript><link rel="stylesheet" href="style.css"></noscript>.
This pattern works because media="print" tells the browser the stylesheet is only needed for printing, so it downloads it at low priority without blocking rendering. When the file finishes loading, the onload handler changes the media to "all", instantly applying the full styles. Users see the correctly-styled above-the-fold content immediately, and the remaining styles apply as soon as they arrive. The transition is seamless because the critical CSS already covers everything visible.
Build Pipeline Integration
For production sites, critical CSS extraction should be automated. Critters (Google's tool, integrated into Angular CLI and available as a webpack/Vite plugin) analyzes your built HTML and inlines critical CSS at build time without a headless browser. Critical by Addy Osmani uses Puppeteer to render the page and extract the exact styles used above the fold. Both tools work with static and server-rendered pages. For Next.js applications, the framework handles critical CSS extraction automatically when using CSS Modules or styled-jsx.
Common Pitfalls
Font declarations in critical CSS: If your above-the-fold content uses custom fonts, the @font-face rules must be in the critical CSS. However, this adds significant size. Consider using font-display: swap and preloading the font file with <link rel="preload" as="font"> instead of inlining the entire font-face declaration.
CSS custom properties (variables): If your critical styles use CSS variables defined in :root, the variable declarations must also be included in the critical CSS. Missing variable definitions cause styles to fall back to initial values, creating a flash of incorrectly-styled content (FOISC).
Over-inlining: Including too much CSS as critical defeats the purpose. If your critical CSS exceeds 14KB, you are likely including styles for elements that are not truly above the fold. Audit each rule and ask: is this element visible without any scrolling on the target viewport? If not, it belongs in the deferred CSS.
Cache invalidation: Inline CSS cannot be cached independently by the browser. On repeat visits, the user re-downloads the critical CSS with every HTML request. This is why you should keep it minimal and still load the full external stylesheet (which is cached) for subsequent page views. The external stylesheet provides the cached version of all styles including the critical ones.
Frequently Asked Questions
What is critical CSS and why does it matter?
Critical CSS is the minimum set of CSS rules needed to render the above-the-fold content. By inlining it in the HTML head and deferring the rest, you eliminate render-blocking stylesheets. This can reduce First Contentful Paint by 500ms-2s.
How do I identify which CSS is above the fold?
Above-the-fold CSS includes styles for elements visible in the initial viewport before scrolling: body base styles, header, navigation, hero section, visible typography, and layout properties for the top section.
How large should inline critical CSS be?
Under 14KB compressed, which fits within the first TCP round-trip. Most well-optimized pages achieve 5-12KB of critical CSS. Larger sizes require additional round-trips, reducing the inlining benefit.
How do I defer non-critical CSS loading?
Use the media-swap pattern: load with media='print' and an onload handler that switches to media='all'. Add a noscript fallback for users without JavaScript.
Should I automate critical CSS extraction in my build pipeline?
Yes. Use tools like Critters (Google), Critical (Addy Osmani), or PurgeCSS in your build pipeline to automatically extract and inline critical CSS during each build.