Find and remove unused CSS slowing your website
Short answer: Most business websites ship far more CSS than any page uses: an entire framework, an old theme, styles for pages that no longer exist. To trim it, measure first with the Coverage panel in Chrome DevTools, which shows used and unused bytes per stylesheet. Then remove dead styles at build time with a tool like PurgeCSS, which reads your templates and keeps only the selectors they use. Safelist classes added by JavaScript, test every page type, and re-measure.
Why unused CSS matters
CSS is render-blocking by default: the browser won't paint the page until it has downloaded and processed the stylesheets in the head. A large stylesheet, most of it unused, delays the first view of every page, especially on slower mobile connections. It also slows editing. Developers are reluctant to delete styles they don't understand, so the file keeps growing.
Common sources of bloat on small business sites:
- A full CSS framework included for a handful of components.
- A purchased theme with styles for dozens of layouts the site doesn't use.
- Page-builder plugins loading their full stylesheet on every page.
- Old campaigns, landing pages and sliders removed from the site but not from the CSS.
- Several versions of the same component, written by different people over the years.
Step 1: measure with Chrome DevTools
Chrome's Coverage panel lets you record a page and see a report of total used and unused bytes for each CSS and JavaScript file, and highlight unused rules in the Sources panel.
- Open DevTools, then the Command Menu, and choose to show Coverage.
- Start recording and reload the page.
- Interact with the page: open menus, trigger modals, submit a form with an error, switch tabs.
- Look at the unused bytes for each stylesheet.
Coverage is per page and per session. A rule unused on the home page may be essential on checkout, and a rule for a hover state only counts if you hovered. Treat the numbers as a guide to where the waste lives, not a list of rules to delete.
Step 2: remove dead CSS automatically
Manually deleting rules from a large stylesheet is risky. Build tools do it more safely by comparing your CSS with your actual markup.
PurgeCSS describes its job simply: it reads your content files, matches the selectors they use and removes the rest of your CSS. You point it at your templates, components and scripts, and it outputs a smaller stylesheet. It works as a command-line tool and with common build tools and bundlers.
Utility-first frameworks often do this built in. Tailwind, for example, scans your source files and generates only the classes it finds.
Step 3: protect classes the scanner can't see
The big risk is removing a style that's actually needed. Scanners read files as text, so they miss classes that only exist at runtime:
- Classes built from strings, such as
"btn-" + colour. - Classes added by third-party scripts, such as a cookie banner, chat widget or carousel.
- Classes from content in your CMS database rather than your templates.
- States toggled by JavaScript, such as
is-openorhas-error.
Tailwind's documentation warns about exactly this: because it scans files as plain text, it can't understand string concatenation or interpolation, so you should always use complete class names. PurgeCSS offers safelisting, where you list classes or patterns to keep regardless of what the scan finds.
Practical rules:
- Write full class names in code, even when choosing between two.
- Add third-party widgets' class prefixes to the safelist.
- Point the scanner at exported CMS templates or content where possible, or safelist the classes editors can use.
Step 4: split what's left
After removing dead code, look at what remains:
- Inline critical CSS for above-the-fold content, and load the rest without blocking rendering.
- Load page-specific CSS only where needed, for example checkout styles on checkout pages.
- Stop plugins loading styles site-wide when they're only used on one page, if your CMS allows it.
Test before you ship
Because removed styles fail silently, test deliberately:
- Visit every template: home, category, product, article, contact, account, checkout, error pages.
- Trigger interactive states: menus, modals, validation errors, empty states, loading states.
- Check emails or PDFs that share stylesheets.
- Use visual regression screenshots if you have them, comparing before and after.
Then re-measure with Coverage and your usual performance tools to confirm the stylesheet is smaller.
Don't forget your own legacy styles
Tools remove CSS for selectors that never appear in your markup, but they can't remove styles that still match something you no longer want, such as an old banner class still present in a footer template, or three competing button styles that all technically apply. Once the automated purge is in place, set aside an hour to read through what remains, merge duplicate components and delete templates that no page uses.
Make it stick
Run the purge step in your build, not by hand, so new code is handled automatically. Keep the safelist in version control with comments explaining each entry. When a component or page is retired, delete its CSS in the same change.
A worked example
Consider a hypothetical Vancouver outdoor clothing store whose theme shipped one large stylesheet with a full framework, a slider library and styles for layouts they'd never used. Coverage on the home and product pages showed most of the CSS unused. Their developer added PurgeCSS to the build, pointing it at theme templates and scripts, safelisted the review widget's and cookie banner's class prefixes, and checked every template. On the first test run, the mobile menu's open state had lost its styles because the class was built from a string in JavaScript. He rewrote it with full class names, then shipped the smaller stylesheet.
FAQ
Can I just delete rules Coverage marks as unused?
Not safely. Coverage only knows about the page and interactions you recorded.
Will this break my CMS editors' styling options?
It can, if editors use classes that don't appear in templates. Safelist those classes or scan the content too.
Does unused CSS affect SEO?
Indirectly. It can slow page rendering, which affects user experience and page performance measurements.
How often should I review CSS size?
After major redesigns, new plugins or theme updates, and whenever performance checks flag render-blocking resources.
If your site's stylesheets have grown out of control, tell us what the site is built with and we'll help slim them down.