1. Paste a page, or CSS and content
2. What it found
Rules that could go
| Byte offset | Selector |
|---|
Every rejected selector
Includes selectors removed from a list whose other selectors are still used, and arguments of :is() and :where().
| Selector |
|---|
How it decides
- The content is cut into words with
[A-Za-z0-9_-]+..cardis used ifcardis a word anywhere, in aclassattribute, a script string or the text. That errs toward keeping rules. - Every class, id, tag and attribute of a selector must be found. Pseudo-classes, pseudo-elements and combinators never count against it.
:is()and:where()arguments are judged one by one;:not()and:has()arguments are always kept.[value],[checked],[selected]and[open]are always kept, since scripts change them.- Rules inside
@keyframes, and@font-faceand custom properties, are left alone.purgecss ignorecomments are honoured.
It can call a rule unused that a visitor does see: a class name your code builds with no literal prefix, markup fetched at run time, or a class set by a script from another site. Check before deleting.
Run it over a whole site
The CLI reads every HTML page under a folder, takes each page's <style> blocks and linked local stylesheets, and judges them against the page, the local scripts it loads and every module those scripts import.
git clone --depth 1 --filter=blob:none --sparse https://github.com/duncan-haywood/oss-monorepo cd oss-monorepo && git sparse-checkout set ventures/csshound cargo install --path ventures/csshound csshound site/ # summary and the worst pages csshound --dead site/ # every unused rule, page:offset: selector csshound --fail site/ # CI gate: exit 1 if anything is unused
Measured on this repository
On 3,915 HTML pages (99,479 rules, 8,101,928 bytes of CSS), on a 4-core container: 0.50 to 0.52 s and 18 to 21 MB. It found 8,815 rules (644,192 bytes, 8.0% of the CSS) that nothing on their page uses. With PurgeCSS's input, which does not follow imports, the count was 13,412: following imports removes a third of the findings. Run against PurgeCSS 9.1.0 itself on 3,923 pages with the same input, the two rejected the same 15,632 selectors, with no difference either way. PurgeCSS took 4.6 to 4.9 s and 123 MB; csshound 0.31 to 0.36 s (1.1 s on one thread) and 10 MB. The benchmark has the commands to repeat it.
Questions
Is my code uploaded?
No. What you paste is handed to a WebAssembly module loaded from this site and judged in this tab. The page makes no network requests of its own after it loads.
How does it decide a rule is unused?
The same way PurgeCSS does by default: the markup and scripts are cut into words, and a selector is unused when one of its classes, ids, tags or attributes is not one of those words. Pseudo-classes and combinators never count against a selector, and rules inside @keyframes are left alone.
Can it be wrong?
Yes, in the direction of calling something unused that a visitor does see: a class name your code builds with no literal prefix, markup fetched at run time, or a class set by a script from another site. It keeps classes built from a literal prefix plus a value, such as "tier-" + level. Check a finding before deleting the rule.
How is this different from PurgeCSS?
It uses PurgeCSS's rules but works page by page over a whole folder, follows the imports of each page's scripts, and reports instead of rewriting files. Given the same input, it rejects exactly what PurgeCSS 9.1.0 rejects: 15,632 selectors on 3,923 pages, no difference either way.