PurgeCSS
Remove unused CSS selectors to dramatically shrink your stylesheet size.
Repository Health
Technical Analysis
PurgeCSS is a tool that analyzes your content files and your CSS, then removes any selectors that are never actually used. For projects built on large utility frameworks like Tailwind or Bootstrap, where only a fraction of the generated classes end up in the markup, this can cut stylesheet size by an order of magnitude and speed up page loads.
It works by extracting the list of selectors present in your HTML, JavaScript, templates, and other content, and comparing them against the rules in your CSS. Anything unmatched is dropped. PurgeCSS ships as a core library with a CLI and integrates into virtually every build pipeline through official PostCSS, webpack, Rollup, Gulp, Grunt, and Vue CLI wrappers, plus pluggable extractors for JSX, TSX, Pug, and more.
What You Get
- A core engine that removes unused CSS based on your content files
- A command-line interface for one-off or scripted runs
- Official integrations for PostCSS, webpack, Rollup, Gulp, and Grunt
- Pluggable extractors for HTML, JSX, TSX, and Pug content
- Safelisting and blocklisting to protect dynamically generated classes
- A programmatic JavaScript/TypeScript API
Common Use Cases
- Shrinking Tailwind or Bootstrap output down to only the classes you use
- Reducing CSS payload as part of a production build step
- Cleaning up legacy stylesheets with accumulated dead rules
- Optimizing CSS in webpack, Rollup, or PostCSS pipelines
Under The Hood
Architecture - The project is a Lerna-managed TypeScript monorepo. The purgecss core package (packages/purgecss/src) exposes the engine via index.ts, with ExtractorResultSets.ts collecting the selectors found in content, options.ts and internal-safelist.ts governing configuration, and bin.ts providing the CLI entry point. Framework wrappers such as postcss-purgecss, purgecss-webpack-plugin, and rollup-plugin-purgecss are thin adapters that feed content and CSS into that core, while purgecss-from-* packages are pluggable extractors for JSX, TSX, Pug, and HTML.
Tech Stack - Written in TypeScript and built with ts-node, distributed as both CommonJS and ESM with type definitions. It uses Lerna for monorepo/workspace management, Jest for testing, and ESLint for linting. The core has minimal runtime dependencies, relying on selector extraction and CSS parsing rather than heavy frameworks.
Code Quality - The core package ships an extensive Jest suite (__tests__) with focused test files for attributes, keyframes, css-variables, font-faces, globs, comments, and more, indicating strong coverage of edge cases. TypeScript types are published, and the monorepo separates concerns cleanly between the engine, the CLI, extractors, and build-tool adapters.
API Design - PurgeCSS offers a small, approachable surface: a PurgeCSS class / function taking content and CSS globs plus options, mirrored by an equivalent CLI. The wide family of official integrations means most users never touch the core directly - they configure a familiar plugin for their build tool - which keeps adoption low-friction. Safelist/blocklist options address the main real-world pitfall (dynamically generated classes) directly.