3.3 Remove unused CSS
Most stylesheets ship far more rules than any page uses.
Remove unused CSS
A typical site using a CSS framework ships a stylesheet where most rules never match anything. Every unused rule costs download time, parse time, and a little matching time.
Find it
The Coverage panel in Chrome DevTools records which rules actually ran. Open it, record, click around, and it reports unused bytes per file.
Read the result carefully. "Unused" means not used during this recording. A modal's styles look unused until someone opens the modal. Coverage tells you where to look, not what to delete.
Remove it
At build time. PurgeCSS scans your templates for class names and drops rules that never appear. Tailwind and most modern CSS frameworks do this by default — if you use one, it is already handled.
The failure mode is dynamically constructed class names:
// PurgeCSS cannot see this; the class gets stripped.
const cls = `text-${color}-500`;
// It can see this.
const cls = { red: "text-red-500", blue: "text-blue-500" }[color];At the source. Deleting dead CSS by hand is safer than it sounds if styles are scoped — CSS modules, single-file components, CSS-in-JS. When styles live next to the component, deleting the component takes its CSS with it.
This is the real fix. Tooling that strips unused rules is a workaround for stylesheets that are not scoped in the first place.
Check your reset
Before adding a normalize or reset file, check whether your framework already includes one. Shipping two is common and entirely wasted.