Building Your Learning Module...
Getting things ready for you!
Find videos you like?
Save to resource drawer for future reference!
Faster page loads with optimized CSS
Smooth animations at 60fps
Efficient selectors that render quickly
Reduce file sizes
Avoid expensive CSS properties
Better user experience
Smaller CSS loads faster
100KB → 20KB with minificationSimple selectors render faster
.button (fast) vs div > * (slow)Some CSS properties are slow
transform (fast) vs box-shadow (slow)Load essential styles first
Above-fold CSS inline/* Lots of whitespace and comments */
.button {
/* Primary button styles */
background-color: #3b82f6;
color: white;
padding: 12px 24px;
border-radius: 6px;
font-size: 16px;
}
.button:hover {
background-color: #2563eb;
}.button{background-color:#3b82f6;color:white;padding:12px 24px;border-radius:6px;font-size:16px}.button:hover{background-color:#2563eb}margin: 10px; instead of 4 separate properties/* ⚡ FAST: Simple class selector */
.button {
background: #3b82f6;
}
/* ⚡ FAST: ID selector (fastest) */
#header {
padding: 20px;
}
/* 🆗 OKAY: 2-3 levels deep */
.nav .item {
padding: 10px;
}
/* 🐌 SLOW: Too many levels */
.container .wrapper .content .item .link {
color: blue;
}
/* 🐌 SLOW: Universal selector */
* {
box-sizing: border-box; /* Only use once for reset */
}
/* 🐌 SLOW: Complex attribute selector */
[class*="btn"][data-type*="primary"] {
background: blue;
}
/* ✅ BETTER: Use a specific class instead */
.btn-primary {
background: blue;
}transform - Super fast!opacity - Very fastcolorbackground-colorbox-shadow (large spreads)filter: blur()position changeswidth/height changes/* 🐌 SLOW: Animating width (causes reflow) */
.box-slow {
width: 100px;
transition: width 0.3s;
}
.box-slow:hover {
width: 200px; /* Slow! Browser recalculates layout */
}
/* ⚡ FAST: Use transform instead */
.box-fast {
width: 100px;
transition: transform 0.3s;
}
.box-fast:hover {
transform: scaleX(2); /* Fast! GPU accelerated */
}
/* 🐌 SLOW: Large box shadow */
.card-slow {
box-shadow: 0 0 100px 50px rgba(0,0,0,0.5); /* Too large! */
}
/* ⚡ FAST: Smaller box shadow */
.card-fast {
box-shadow: 0 2px 4px rgba(0,0,0,0.1); /* Much faster */
}
/* ⚡ FAST: Use will-change for animations */
.animated-element {
will-change: transform, opacity; /* Tells browser to optimize */
}
.animated-element.active {
transform: translateX(100px);
opacity: 0.5;
}Critical CSS is the minimum CSS needed to render the top of your page (above the fold). Load it inline in the HTML <head>, and load the rest later.
<!DOCTYPE html>
<html>
<head>
<title>My Site</title>
<!-- INLINE critical CSS for instant rendering -->
<style>
/* Only styles for above-the-fold content */
body { margin: 0; font-family: sans-serif; }
.header { background: #3b82f6; padding: 20px; color: white; }
.hero { padding: 60px 20px; text-align: center; }
.hero h1 { font-size: 48px; margin: 0; }
</style>
<!-- Load full CSS asynchronously -->
<link rel="preload" href="styles.css" as="style" onload="this.onload=null;this.rel='stylesheet'">
<noscript><link rel="stylesheet" href="styles.css"></noscript>
</head>
<body>
<header class="header">My Site</header>
<section class="hero">
<h1>Welcome!</h1>
</section>
<!-- Rest of page... -->
</body>
</html><div class="demo">
<h2>Hover over each box to see performance</h2>
<div class="boxes">
<div class="box box-slow">
<h3>🐌 Slow</h3>
<p>Animates width (causes reflow)</p>
</div>
<div class="box box-fast">
<h3>⚡ Fast</h3>
<p>Uses transform (GPU accelerated)</p>
</div>
</div>
<p class="note">Notice how the fast animation feels smoother!</p>
</div>Loading preview...
Limited CPU power needs optimization
Millions of visitors = performance critical
Smooth 60fps animations required
Every 100ms delay = 1% lost sales
Chrome DevTools: Performance tab shows CSS rendering time
Lighthouse: Google's tool for performance audits
WebPageTest: Test from different locations and devices
CSS Stats: Analyze your CSS complexity and size