Find and remove unused CSS in React & Next.js
Every design iteration leaves residue: .oldCard from a layout you replaced two sprints ago, utility classes from an experiment that never shipped, a whole Button.module.css whose component got rewritten inline. Nothing imports them, nothing renders them - but they still ship to your users and still confuse whoever reads the stylesheet next. DeadCode finds them mechanically, then removes them only after you have seen exactly what would change.
Last updated: 2026-08-22 · DeadCode on GitHub
--dry-run until you trust the report.Install
DeadCode is MIT-licensed and dependency-free. A bare pip install deadcode will NOT get this tool - it is not on public PyPI yet.
Why unused CSS keeps shipping
Tree-shaking handles JavaScript reasonably well, but stylesheet dead weight slips through most pipelines. CSS modules are imported wholesale - if one class in the file is used, the entire file ships. Over months of feature work, the gap between what your stylesheets define and what your components reference only grows, and no linter flags it because nothing is technically "broken."
The fix is a mechanical audit: diff what is defined against what is referenced, across your whole repo at once.
Scan for orphaned CSS
deadcode scan -c orphaned_css # quick overview of all four dead-code categories first, if you prefer: deadcode stats
DeadCode's orphaned_css category reports CSS classes that exist in your stylesheets but are never referenced by any TSX/JSX file - for example .oldClass sitting in styles.module.css with zero usages anywhere in the project. The scan covers export/import patterns, route detection, CSS class usage, and component references across the entire codebase, so one pass gives you the full picture rather than file-by-file guesswork.
Preview before you delete anything
This is the part worth trusting the tool for: removal is preview-first, and conservative by design.
# show exactly what would change - writes nothing deadcode remove --dry-run # scope the preview (and the removal) to CSS only deadcode remove --dry-run -c orphaned_css
The remover only blanks self-contained single-line findings. Anything spanning multiple lines is skipped with a warning instead of being cut - so it never leaves half-deleted, broken code behind. When the dry-run looks right:
deadcode remove -c orphaned_css
Gate CI on new dead styles
Cleanup without enforcement re-accumulates within a quarter. Add a threshold check to CI so a PR that introduces fresh orphaned CSS fails loudly instead of merging quietly:
deadcode scan -c orphaned_css --fail 5 # exit non-zero above 5 findings
What free vs paid gets you
| Free ($0) | Individual ($12/mo) | |
|---|---|---|
| Scan all 4 categories incl. orphaned CSS | Yes (rate-limited) | Yes, unlimited |
| Works offline, no telemetry | Yes | Yes |
| Auto-removal with --dry-run preview | No | Yes |
| CI integration (--fail thresholds) | No | Yes |
A $49/mo Suite license covers all eleven tools in the family if you want the same treatment for exports, routes, config drift, and infra plans too.
Frequently asked questions
Does scanning cost anything?
No. Scanning - including the orphaned_css category - works on the free tier, which runs fully offline with no telemetry; it is rate-limited. Unlimited scans, auto-removal, and CI gating are the Individual tier at $12/mo ($10/mo billed annually).
Can it break my styles?
Every removal starts with a --dry-run preview, and the remover blanks only self-contained single-line findings. Multi-line blocks are skipped with a warning, never partially deleted.
What about dynamically built class names like styles[prefix + name]?
Dynamically composed references can look unused to any static scan. That is why the workflow is preview-first: read the dry-run output, whitelist anything dynamic, and let the safe single-line remover handle the rest.
Is DeadCode on public PyPI?
Not yet - publishing is pending. The documented working install is pip install git+https://github.com/Coding-Dev-Tools/deadcode.git; Homebrew users can tap Coding-Dev-Tools/tap.
See what your stylesheets forgot to delete
One command shows every CSS class, export, route, and component your project stopped using - preview-first, offline, MIT-licensed.
Try DeadCode free →