CSS Performance Optimization: Render-Blocking Stylesheets, Critical CSS and Unused Rules
Why stylesheets block rendering, how to inline critical CSS safely, and why a Coverage report is not a delete list.
In short
CSS has one property that makes it a performance problem: the browser will not paint anything until its stylesheets have arrived. That is deliberate — nobody wants to see unstyled content flash and then rearrange — but it means a slow stylesheet leaves your page blank even though all its content was delivered in the first response.
Three things to fix, in order:
- Stop stylesheets blocking the first paint — inline what the first screen needs, load the rest without blocking.
- Ship less CSS per page — split by template rather than one stylesheet for the whole site.
- Reduce the cost of what remains — expensive selectors, layout-triggering properties, very large documents.
And one thing not to do carelessly: deleting "unused" CSS from a Coverage report. That report describes one page in one state, and it has broken a great many live sites.
Why CSS blocks rendering
When the browser parses your HTML and finds a <link rel="stylesheet">, it keeps reading the HTML but will not paint until that stylesheet is downloaded and parsed. It needs the complete picture: a rule at the end of the file could change everything above it.
The consequence is that your first paint is gated on your slowest blocking stylesheet. A 200 KB stylesheet on a slow connection is a second of blank screen, regardless of how fast your HTML and images were.
You can see this working in our performance lab — two identical pages, one blocked on a slow stylesheet and one with the same styles inlined. The content is in the HTML on both; only the ability to paint it differs.
What else blocks
@import inside a stylesheet is the worst case. The browser cannot discover the imported file until the importing file has downloaded and been parsed, so the downloads happen one after another instead of together. Remove @import from anything on the critical path.
Synchronous scripts block HTML parsing, and a script before your stylesheet can delay it. Covered in the JavaScript guide.
Critical CSS: the main fix
The idea is simple. Take the styles needed to render what the visitor sees first, put them directly in the document so nothing has to be fetched, and load the rest without blocking.
<head>
<style>
/* Only what the first screen needs: layout, header, hero, typography */
:root { --ink: #18210f; }
body { margin: 0; font: 16px/1.6 system-ui, sans-serif; color: var(--ink); }
.header { display: flex; align-items: center; padding: 16px 24px; }
.hero { min-height: 60vh; }
.hero h1 { font-size: clamp(1.8rem, 4vw, 3rem); }
</style>
<!-- The rest, loaded without blocking the first paint -->
<link rel="preload" href="/styles.css" as="style" onload="this.rel='stylesheet'">
<noscript><link rel="stylesheet" href="/styles.css"></noscript>
</head>
The onload trick is the standard non-blocking pattern: preload fetches it at low priority without blocking, then the handler promotes it to a stylesheet. The <noscript> fallback covers browsers without JavaScript.
The hard part is keeping it current
Critical CSS is easy to generate once and hard to maintain. The styles the first screen needs change every time a template changes, and stale critical CSS produces a flash of wrongly styled content — worse than the problem it solved.
Two sustainable approaches:
Generate it in your build. Tools extract the above-the-fold CSS per template automatically, so it cannot drift.
Keep the inline block deliberately small and hand-written. A genuinely minimal block — layout, header, hero, base typography — changes rarely and is easy to review. This is often more maintainable than automation for a site with few templates.
Either way: inline the minimum, not the stylesheet. Inlined CSS is not cached between pages, so every inlined byte is paid for on every page view.
Shipping less CSS per page
A single stylesheet for the whole site means a policy page downloads the styles for your product gallery, your checkout and your blog.
Split by template. One shared base plus per-template files is usually the right shape.
Load conditional CSS with a media attribute. A stylesheet with a media attribute that does not match is fetched at low priority and does not block rendering:
<link rel="stylesheet" href="/print.css" media="print">
<link rel="stylesheet" href="/wide.css" media="(min-width: 1200px)">
Remove frameworks you barely use. Shipping a full framework for a grid and two buttons is a common and expensive habit.
Unused CSS: the honest version
This is where people break their sites, so it deserves care.
DevTools → Coverage panel (Ctrl+Shift+P, "Show Coverage") reports how much of each stylesheet was used. It is genuinely useful, and it is not a delete list.
What "unused" means there is: not applied during that particular page load, in that particular state, at that particular viewport. It knows nothing about:
- Hover, focus and active states — nobody hovered anything during the test.
- Other breakpoints — the report reflects one viewport width.
- Dynamic classes — anything JavaScript adds when a menu opens, a modal shows, a form errors.
- Other templates — a shared stylesheet is "unused" on any page that does not need its rules.
- Print styles.
- States you did not reach — empty cart, out of stock, logged in, error pages.
A safer order of operations
- Split by template first. Most of your "unused" CSS is used — just not here.
- Remove whole components you have genuinely retired, where you can confirm the markup is gone too.
- Only then consider individual rules, and only with a full state and breakpoint test.
Reducing the cost of the CSS you keep
Beyond bytes, CSS costs time to apply.
Avoid layout-triggering animation. Animating height, width, top or margin forces the browser to recalculate layout on every frame. Animate transform and opacity, which the compositor handles.
/* Recalculates layout 60 times a second */
.panel { transition: height 0.3s; }
/* Does not */
.panel { transition: transform 0.3s, opacity 0.3s; }
Use content-visibility for long pages. It lets the browser skip rendering work for sections far below the viewport, which is a cheap win on long collection and article pages.
.section-below-fold {
content-visibility: auto;
contain-intrinsic-size: auto 600px; /* an estimate, so the scrollbar behaves */
}
Keep the document from getting enormous. CSS cost scales with the number of elements it has to be applied to, so a page with thousands of elements makes every style recalculation more expensive — disproportionately so on a phone.
Selector complexity matters less than people think on modern browsers. Do not spend time micro-optimising selectors; spend it on blocking, volume and layout work.
Platform differences
Shopify. Theme CSS is yours, so inlining critical CSS in theme.liquid and splitting per template are both available. App stylesheets are not yours to change. Watch for stylesheet_tag, which produces a blocking link.
WordPress. Plugins enqueue stylesheets site-wide by default, so pages load CSS for features they do not have. Conditional dequeuing per template is usually the biggest available win, and is safer than editing plugin CSS.
Custom builds. Generate critical CSS in the build so it cannot drift, and split by route.
Hosted builders. The platform generates and serves the stylesheet, so you generally cannot split it or inline part of it. Reducing unused classes and interactions in the editor indirectly reduces what is generated. See what your platform allows.
Common mistakes
Deleting rules from a Coverage report without testing states, breakpoints and templates.
Generating critical CSS once and letting it go stale, producing a flash of wrong styling.
Inlining the whole stylesheet, which makes the HTML large and uncacheable.
Leaving @import on the critical path.
Minifying and expecting the blank screen to go away. Minification reduces bytes; blocking is about when the file is needed.
Animating layout properties and wondering why scrolling stutters.
Micro-optimising selectors instead of fixing blocking and volume.
Testing with a warm cache, where the stylesheet is already local and nothing blocks.
Verification
- Record with Screenshots on and compare the filmstrip. The white frames at the start should be gone or much shorter.
- Check First Contentful Paint dropped, under the same throttling, median of five runs.
- Confirm no stylesheet is on the critical path in the Network panel.
- Look for a flash of unstyled content. If the page appears and then restyles, your critical CSS is incomplete or stale.
- Test every breakpoint and interactive state you touched — especially if you removed anything.
- Check CLS. Incomplete critical CSS causes layout to change when the full stylesheet arrives.
- Then watch field data for four weeks.
When it still does not improve
- Still blank at the start → something else is blocking. Check for a synchronous script before your stylesheet, or an
@import. - FCP improved but LCP did not → your LCP element is waiting on something else, probably an image discovered late.
- A flash of unstyled content appeared → the inline block is missing styles the first screen needs. Add them, or reduce what is above the fold.
- The layout shifts when the full stylesheet loads → same cause. The inline block must be complete enough to lay out the first screen correctly.
- You split the CSS and nothing changed → the stylesheet may not have been the bottleneck. Re-record and check what is actually on the critical path.
- It is fine for you and slow for visitors → test with an empty cache and throttling. Your stylesheet is cached; theirs is not.
Keeping it fixed
CSS grows, and critical CSS drifts. Both happen quietly.
Three habits: generate critical CSS in the build rather than by hand if you have more than a few templates; set a budget on total CSS per template and check it before release; and include "does the page paint without waiting for a stylesheet?" in your pre-release check, because that is the failure that matters most and is the easiest to reintroduce.
Frequently asked questions
Why does CSS block rendering?
Because the browser needs the complete stylesheet before it can paint — a rule at the end of the file could change everything above it. Showing unstyled content and then restyling it would be worse, so the browser waits. The result is that your first paint is gated on your slowest blocking stylesheet.
What is critical CSS?
The subset of styles needed to render what the visitor sees first, written directly into the document so nothing has to be fetched before painting. The rest of the stylesheet is then loaded without blocking. Inline the minimum, not the stylesheet — inlined CSS is not cached between pages.
Can I delete the unused CSS that the Coverage panel reports?
Not safely. "Unused" means not applied during that one page load, at that one viewport, in that one state. It knows nothing about hover and focus states, other breakpoints, print styles, classes added by JavaScript, other templates, or states like empty cart or logged in. Split CSS per template instead — it is reversible and cannot break a state you forgot to test.
How do I load CSS without blocking rendering?
Preload it as a style and promote it to a stylesheet on load, with a noscript fallback. A stylesheet with a non-matching media attribute — print, or a min-width that does not apply — is also fetched without blocking.
Does minifying CSS help performance?
A little, and less than people expect once Brotli compression is enabled, since compression already handles repeated whitespace well. It does nothing about blocking, which is usually the real problem.
Do complex CSS selectors slow down a page?
Far less than people think on modern browsers. Do not spend time micro-optimising selectors. Spend it on render-blocking, on shipping less CSS per page, and on avoiding animation of layout properties.
References
- Defer non-critical CSS — web.dev
- Find unused CSS with the Coverage tool — Chrome DevTools
- content-visibility — MDN
- Render-blocking resources — web.dev