Remove Unused CSS Online: Purge Rules Your HTML Never Uses
Paste a page's HTML (or JS markup) and its stylesheet, press Purge CSS, and you get the stylesheet back without the rules that nothing in the markup can match, with the bytes saved shown. You can paste text, use Choose a file or drop a file onto either box, up to 5 MB each. It works in your browser, so your code is not uploaded.
How to remove unused CSS from HTML
- Paste your HTML or JS markup into HTML / markup, or press Choose a file to load it. Clear empties a box.
- Paste your stylesheet into CSS stylesheet the same way.
- If your scripts add classes at runtime, open Advanced and list them in Safelist (see below).
- Press Purge CSS. The button stays disabled until both boxes have text.
- Read Purged CSS, then press Copy to clipboard (it changes to Copied) or Download CSS to save
purged.css. - Press Edit input to go back with your text kept, for example to add a safelist entry and purge again.
The result shows a line such as NN% smaller with Original and Purged sizes beside it. If no rule is left, you see "No rules were left. Check that this HTML belongs to this stylesheet, or add selectors to the safelist." That usually means the markup and the stylesheet are from different pages.
What counts as unused
The tool reads every word in your markup and keeps a rule only if every class, ID, tag and attribute name in its selector appears there. Class and ID names are case-sensitive.
Pseudo-classes and pseudo-elements such as :hover or ::before are never required, and whatever is inside :not() or :is() is ignored.
For markup like the example below, here is what happens to each rule in the stylesheet:
btn and a div with the class card, and no other classes.
| Rule in your CSS | Result | Why |
|---|---|---|
.btn:hover | Kept | btn is in the markup; :hover is never required |
.card, .modal | Becomes .card | In a comma list only the unused selectors go |
.footer | Removed | footer is not in the markup |
@media (min-width:600px) holding only .sidebar rules | Whole block removed | An at-rule left empty is dropped |
@keyframes spin | Kept | Never purged |
Rules inside @media, @supports, @layer and @container are purged inside, and the at-rule goes only when nothing is left in it.
@font-face, @keyframes, @import, @charset, @page and @property are always kept, and so are :root, custom properties, the * selector, html and body.
Keep classes your JavaScript adds with the Safelist
Open Advanced to find Safelist. Type classes or IDs to keep even when they are not in the HTML, separated by commas, for example .modal, #nav, is-active.
The leading . or # is optional.
- A safelisted name keeps rules that mention it.
- The rest of that selector still has to match, so
.menu.is-activestays only ifmenuis also in the markup. - Names written out in JS you paste into HTML / markup are found without a safelist. Names built in code, such as
'btn-' + size, are not.
Remove unused CSS across several pages, Tailwind and WordPress
One stylesheet usually serves many pages. Paste the markup of all of them, one after another, into HTML / markup, and a rule is kept if any page uses it.
For Tailwind, paste your templates and the built stylesheet: escaped selectors such as md\:flex and w-1\/2 match the class names written in the markup.
For a WordPress theme, copy the page source of each page type the theme shows, and paste the theme's stylesheet.
What this does not know
It does not run your page or your JavaScript. It only reads the text you paste, so a class that appears only at runtime, or in a page you did not paste, is treated as unused. Check the purged stylesheet on the real page before you ship it.
Kept rules are not reformatted or minified, and comments are removed except /*! license */ ones. A stylesheet that was minified onto one line stays on one line.
Frequently asked questions
How do I remove unused CSS from HTML?
Paste the page's HTML into HTML / markup and your stylesheet into CSS stylesheet, then press Purge CSS. Purged CSS shows the stylesheet with every rule the markup cannot match removed, plus the percentage saved. Press Copy to clipboard or Download CSS (the file is purged.css) and replace the old stylesheet.
Is there a PurgeCSS online tool?
This is an online tool for the same job. It reads every word in your markup and keeps a rule only if each class, ID, tag and attribute name in its selector appears there. It is not the PurgeCSS package, so it has no config file or plugins, and it does not run your page. The Safelist field covers the one option most people need.
How do I find unused CSS classes?
Press Purge CSS and compare the result with your original. Any class that has disappeared from Purged CSS had no match in the markup you pasted. The tool does not list the removed rules, so for a long stylesheet it helps to check the Original and Purged sizes first and then look at what is missing.
How do I keep classes that JavaScript adds later?
Open Advanced and type them in the Safelist field, separated by commas, for example .modal, #nav, is-active. The leading . or # is optional. Rules that mention a safelisted class or ID are kept, but the rest of the selector must still match, so .menu.is-active stays only if menu appears in the markup too. If your JavaScript is part of what you paste into HTML / markup, class names written out in it are found without a safelist.
Why was a class my script adds removed from the CSS?
The tool does not run your page or your JavaScript. It only reads the text you paste, so a name built at runtime, such as 'btn-' + size, never appears and its rules are removed. Paste the script into HTML / markup, write the full class names there, or add them to the Safelist. Then check the result on the page before you ship it.
How do I purge CSS for Tailwind?
Paste your templates or components into HTML / markup and the built Tailwind stylesheet into CSS stylesheet. Escaped selectors such as md\:flex and w-1\/2 are matched against the class names written in the markup, so those utilities stay when you use them. Class names assembled in code, like 'bg-' + color + '-500', are not found, so write them out in full or safelist them.
How do I remove unused CSS in WordPress without a plugin?
Open a page, view its source, copy the HTML and paste it into HTML / markup. Paste your theme's stylesheet into CSS stylesheet and press Purge CSS. A theme stylesheet is shared by many pages, so paste the HTML of several different pages, one after another, into the same box; a rule is kept if any of them uses it. Replace the file only after checking each page type.
Can I remove unused CSS across several pages at once?
Yes. Put the markup of all the pages into HTML / markup, one after another, up to 5 MB in total. A rule survives if the combined text matches it, so nothing used on any one page is lost. Pages you leave out are treated as not using the rule.
Does removing unused CSS also minify it?
No. Kept rules are left as you wrote them, not reformatted or minified, and a stylesheet that was one line stays one line. Comments are removed except /*! license */ ones. To shrink the file further, run the result through the CSS Minifier.
Is my HTML or CSS uploaded anywhere?
No. The purge runs in a Web Worker in your browser, so the markup and stylesheet stay on your device. Each box takes up to 5 MB.
Recommended
-
Quntis Monitor Light BarCheck your slimmed-down stylesheet on a lit desk, with a bar that adds no glare to the screen.
-
Anker 7-in-1 USB-C Hub (SD, HDMI)One hub to plug in the SD card and HDMI display you use to review the site before you ship it.
-
ARZOPA 16" 144 Hz Portable MonitorKeep the live page on a second screen and test it while you cut CSS in the first.
Helps keep the tools free. ✨
Images are for illustration only. As an Amazon Associate I earn from qualifying purchases.