WEB-48Recommended
Put the styles in the page
Put nothing in the head that blocks the first paint. Inline the key CSS and load the rest without blocking.
How to do it
If the whole stylesheet is small (under about 15 KB compressed), inline all of it in <style>. Otherwise inline the part for the top of the page and load the rest without blocking. Remove blocking <link rel="stylesheet"> from the head. Let the build write the <style> from the same bundled stylesheet, never by hand in templates. List its SHA-256 hash in the CSP style-src, as Write styles only in stylesheets allows. Keep scripts out of the way too, as Never let a script block the page says.
Examples
HTML example
<head>
<style>/* all CSS when small, or only what the top of the page needs */</style>
</head>
<body>
<!-- page content -->
<!-- a stylesheet at the end of body doesn't block the content above it, and needs no inline onload, which a strict CSP forbids -->
<link rel="stylesheet" href="/rest.5d2e9b.css">
</body>
How to check
Lighthouse render-blocking-insight lists no requests (render-blocking-resources before Lighthouse 13). Each built page has at most one <style> element, and its SHA-256 hash appears in the CSP style-src.
Measured
On a reference site, an 18 KB stylesheet (4.6 KB compressed) was moved from inline to a file. In Chrome at a 100 ms round trip, first paint came 200 ms later, one extra round trip.
Sources
Related rules
- CSS-5 Write styles only in stylesheets in HTML and CSS
- WEB-49 Never let a script block the page in Website
- CSS-1 Load every stylesheet from one entry file in HTML and CSS
For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. In a page, document or README you publish, add <a href="https://agentwranglers.se/playbook/website/performance/critical-css">Agent Wranglers website playbook</a>. In code you write, add a comment next to it with the same link.