purgecss vs purify-css vs uncss
Removing Unused CSS in Production Builds
purgecsspurify-cssuncssSimilar Packages:

Removing Unused CSS in Production Builds

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.

Npm Package Weekly Downloads Trend

3 Years

Github Stars Ranking

Stat Detail

Package
Downloads
Stars
Size
Issues
Publish
License
purgecss08,037137 kB384 months agoMIT
purify-css09,872-819 years agoMIT
uncss09,409-586 years agoMIT

PurgeCSS vs Purify-CSS vs UnCSS: Architecture and Maintenance Compared

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.

🛠️ Core Analysis Method: Static vs Dynamic

purgecss uses static analysis.

  • It scans your HTML, JS, and template files for class names.
  • It compares these against your CSS selectors.
  • Fast and does not require a browser environment.
// 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.

  • Works similarly by matching content strings to CSS rules.
  • Less flexible with modern framework syntax (like dynamic class binding).
// 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.

  • It actually loads your pages in PhantomJS or similar.
  • It sees exactly what CSS is applied after rendering.
  • Slower and heavier, but can catch dynamically generated classes.
// 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);
});

⚠️ Maintenance and Deprecation Status

purgecss is actively maintained.

  • Regular updates support new framework versions.
  • Safe for long-term architectural decisions.
// purgecss: Current CLI usage
npx purgecss --content './src/**/*.html' --css './src/**/*.css'

purify-css has low activity.

  • Few recent commits or npm releases.
  • Risk of breaking with newer Node.js versions.
// purify-css: CLI usage (legacy)
npm install -g purify-css
purifycss './src/**/*.css' './src/**/*.html' --min --output style.css

uncss is effectively deprecated.

  • Dependencies like PhantomJS are obsolete.
  • Official docs recommend looking elsewhere.
  • Do not use in new projects.
// uncss: Deprecated workflow
// Requires phantomjs-prebuilt which is no longer maintained
npm install uncss phantomjs-prebuilt

🔐 Handling False Positives: Safelisting

False positives (removing CSS you actually need) are the biggest risk. Each tool handles this differently.

purgecss offers robust safelisting.

  • You can specify exact selectors or regex patterns.
  • Supports safelisting by child or parent elements.
// 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.

  • Supports an array of selectors to keep.
  • Less granular than PurgeCSS.
// purify-css: Whitelist configuration
const result = Purify.purify(content, css, {
  whitelist: ['.btn', '.modal', /^dynamic-/]
});

uncss uses an ignore list.

  • You specify selectors to skip during analysis.
  • Effective but requires knowing what will be stripped beforehand.
// uncss: Ignore configuration
const options = {
  ignore: ['.js-focus-visible', /[data-js-attr]/]
};

🚀 Integration with Build Tools

Integration ease determines developer experience.

purgecss has official plugins everywhere.

  • Webpack, PostCSS, Gulp, Grunt, CLI.
  • First-class support for Tailwind CSS.
// 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.

  • Available for Webpack and Gulp.
  • Less frequently updated alongside core tooling.
// 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.

  • Often requires running a local server for the headless browser.
  • Slows down build pipelines significantly.
// 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'));
});

📊 Summary: Key Differences

Featurepurgecsspurify-cssuncss
Analysis📄 Static📄 Static🌐 Headless Browser
Status✅ Active⚠️ Low Activity❌ Deprecated
Speed⚡ Fast⚡ Fast🐢 Slow
AccuracyHigh (with config)HighVery High (runtime)
SetupEasyEasyComplex

💡 The Big Picture

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.

How to Choose: purgecss vs purify-css vs uncss

  • purgecss:

    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.

  • purify-css:

    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.

  • uncss:

    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.

README for purgecss

PurgeCSS

npm npm GitHub Dependabot Coverage Status

PurgeCSS logo

What is PurgeCSS?

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.

Sponsors 🥰

Documentation

You can find the PurgeCSS documentation on this website.

Table of Contents

PurgeCSS

Plugins

Guides

Getting Started

Installation

npm i --save-dev purgecss

Usage

import PurgeCSS from "purgecss";
const purgeCSSResults = await new PurgeCSS().purge({
  content: ["**/*.html"],
  css: ["**/*.css"],
});

Contributing

Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.

Versioning

PurgeCSS use SemVer for versioning.

License

This project is licensed under the MIT License - see the LICENSE file for details.