Lesson 38 of 50
cssCSS Performance – Critical CSS & Unused CSS
9 mins
Course progress76%
What you'll learn
Keep these ideas in mind as you work through the lesson.
Lesson 38 of 50
css9 mins
Keep these ideas in mind as you work through the lesson.
Performance is the difference between a good and a great website. Two common bottlenecks are large, unused CSS and render‑blocking CSS.
<head> so the browser can render immediately.<head>
<style>
/* Critical rules – hero, navigation, primary typography */
.hero{background:#222;color:#fff;padding:4rem;}
.nav{display:flex;gap:1rem;}
</style>
<link rel="preload" href="/css/main.css" as="style" onload="this.rel='stylesheet'">
<noscript><link rel="stylesheet" href="/css/main.css"></noscript>
</head>
postcss.config.js to strip classes you never use.module.exports = {
content: ['./src/**/*.html', './src/**/*.js'],
safelist: ['bg-red-500','text-center'], // keep if generated dynamically
};
font-display:swap on @font-face to avoid FOIT (Flash of invisible text).contain to limit re‑paint scope (see Lesson 48).Avoid delaying essential styles (like focus outlines) – they must be present before the user can interact.