purgecss, purify-css, and uncss are tools designed to analyze your content and CSS files to remove unused selectors, reducing final bundle size. purgecss is the modern standard, supporting various build tools and frameworks with a robust API. purify-css was an earlier attempt at solving this problem but has seen significantly less activity in recent years. uncss pioneered the concept by using a headless browser to render pages but faces maintenance challenges and dependency issues in modern workflows. All three aim to optimize performance by stripping dead code, but they differ in architecture, maintenance status, and integration complexity.
Removing unused CSS is critical for performance, but choosing the right tool requires understanding how they analyze your code. purgecss, purify-css, and uncss all solve this problem but use different methods and have vastly different maintenance statuses. Let's look at how they work under the hood.
purgecss uses static analysis.
// purgecss: Static analysis configuration
const PurgeCSS = require('purgecss');
const result = await new PurgeCSS().purge({
content: ['./src/**/*.html', './src/**/*.js'],
css: ['./src/**/*.css']
});
purify-css also uses static analysis.
// purify-css: Static analysis configuration
const Purify = require('purify-css');
const result = Purify.purify(
['./src/**/*.html', './src/**/*.js'],
['./src/**/*.css'],
{ minify: true }
);
uncss uses dynamic analysis via a headless browser.
// uncss: Dynamic analysis configuration
const uncss = require('uncss');
const options = {
html: ['http://localhost:3000', './src/**/*.html'],
ignore: ['.js-focus-visible']
};
uncss(options, (error, output) => {
console.log(output);
});
purgecss is actively maintained.
// purgecss: Current CLI usage
npx purgecss --content './src/**/*.html' --css './src/**/*.css'
purify-css has low activity.
// purify-css: CLI usage (legacy)
npm install -g purify-css
purifycss './src/**/*.css' './src/**/*.html' --min --output style.css
uncss is effectively deprecated.
// uncss: Deprecated workflow
// Requires phantomjs-prebuilt which is no longer maintained
npm install uncss phantomjs-prebuilt
False positives (removing CSS you actually need) are the biggest risk. Each tool handles this differently.
purgecss offers robust safelisting.
// purgecss: Safelisting configuration
const result = await new PurgeCSS().purge({
content: ['./src/**/*.html'],
css: ['./src/**/*.css'],
safelist: {
standard: [/^btn/, 'modal'],
deep: [/^child-/],
greedy: [/^header/]
}
});
purify-css has basic whitelisting.
// purify-css: Whitelist configuration
const result = Purify.purify(content, css, {
whitelist: ['.btn', '.modal', /^dynamic-/]
});
uncss uses an ignore list.
// uncss: Ignore configuration
const options = {
ignore: ['.js-focus-visible', /[data-js-attr]/]
};
Integration ease determines developer experience.
purgecss has official plugins everywhere.
// purgecss: Webpack plugin
const { PurgecssPlugin } = require('purgecss-webpack-plugin');
// In webpack.config.js
plugins: [
new PurgecssPlugin({
paths: glob.sync(`${PATHS.src}/**/*`, { nodir: true })
})
]
purify-css has community plugins.
// purify-css: Webpack plugin
const PurifyCSSPlugin = require('purifycss-webpack');
// In webpack.config.js
plugins: [
new PurifyCSSPlugin({
paths: glob.sync(path.join(__dirname, 'src/*.html'))
})
]
uncss is harder to integrate.
// uncss: Gulp task example
const uncss = require('gulp-uncss');
gulp.task('css', function () {
return gulp.src('src/**/*.css')
.pipe(uncss({ html: ['http://localhost:3000'] }))
.pipe(gulp.dest('dist'));
});
| Feature | purgecss | purify-css | uncss |
|---|---|---|---|
| Analysis | 📄 Static | 📄 Static | 🌐 Headless Browser |
| Status | ✅ Active | ⚠️ Low Activity | ❌ Deprecated |
| Speed | ⚡ Fast | ⚡ Fast | 🐢 Slow |
| Accuracy | High (with config) | High | Very High (runtime) |
| Setup | Easy | Easy | Complex |
purgecss is the industry standard 🏆. It provides the best mix of speed, safety, and ecosystem support. It is the default choice for modern stacks, especially with utility-first frameworks like Tailwind.
purify-css is a legacy alternative 🕰️. It works, but lacks the momentum and safety features of PurgeCSS. Only use if you are locked into an older pipeline.
uncss is obsolete 🛑. While its runtime analysis was innovative, the reliance on PhantomJS and lack of maintenance makes it unsuitable for modern CI/CD pipelines. Migrate to purgecss for better stability.
Final Thought: For production applications, reliability matters most. purgecss wins because it is actively kept up to date with the changing JavaScript and CSS landscapes, whereas the others have fallen behind.
Choose purgecss for any new project or modern stack (React, Vue, Tailwind). It is actively maintained, supports safelisting patterns, and integrates seamlessly with Webpack, PostCSS, and CLI workflows. It offers the best balance of accuracy and performance without requiring a full headless browser setup.
Avoid purify-css for new architectures. While it functions similarly to PurgeCSS, it lacks the active community support and recent feature updates found in purgecss. Only consider it if you are maintaining a legacy codebase that already depends on it and migration costs are prohibitive.
Do not use uncss in new projects. It relies on headless browser rendering which is slow and complex to configure compared to static analysis tools. The package has shown signs of stagnation and dependency rot. Evaluate purgecss as a direct, faster, and more reliable alternative.
When you are building a website, chances are that you are using a css framework like Bootstrap, Materializecss, Foundation, etc... But you will only use a small set of the framework and a lot of unused css styles will be included.
This is where PurgeCSS comes into play. PurgeCSS analyzes your content and your css files. Then it matches the selectors used in your files with the one in your content files. It removes unused selectors from your css, resulting in smaller css files.
You can find the PurgeCSS documentation on this website.
npm i --save-dev purgecss
import PurgeCSS from "purgecss";
const purgeCSSResults = await new PurgeCSS().purge({
content: ["**/*.html"],
css: ["**/*.css"],
});
Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.
PurgeCSS use SemVer for versioning.
This project is licensed under the MIT License - see the LICENSE file for details.