BASE

PurgeCSS

PurgeCSS

Build / code quality tool · Free

Removes unused CSS rules based on content sources: it helps reduce website style output while preserving required dynamic classes.

Also known as: FullHuman/purgecss; purge-css; css-purge

Resource illustration: PurgeCSS

Open resource ↗

What you can use for free

Code and local use under MIT.

Paid features and costs

Computing resources, self-hosting, and external services are paid for separately if used.

Access and limitations

Code and local use under MIT. Computing resources, self-hosting, and external services are paid for separately if used.

Use cases

  • Reduce CSS output without losing used styles
  • Add exceptions for dynamic classes and compare styles before and after cleanup

Example workflow

A possible workflow; this is not a report of hands-on testing.

Reduce CSS output without losing used styles.

Before you start

  • A repository, package manifests, and configuration.
  • A compatible runtime and the target build command.

Steps

  1. Specify content sources containing used CSS classes.
  2. Add exceptions for dynamic classes and compare styles before and after cleanup.
  3. Add the workflow to scripts or CI with a clear report.

Check your result

  • A clean copy of the project reproduces the result.
  • Errors produce a nonzero exit code and clear diagnostics.

Choosing PurgeCSS

Reduce CSS output without losing used styles

Choose this when

  • Reduce CSS output without losing used styles
  • Add exceptions for dynamic classes and compare styles before and after cleanup

Requirements

  • Set a safelist for dynamically generated classes; check PostCSS processing order for exclusion comments.

Things to consider

  • Costs and limits of free use: Computing resources, self-hosting, and external services are paid for separately if used.
  • Terms of use: MIT for the code; dependencies have separate licenses.
  • A CSS optimizer may remove the purgecss ignore comment before PurgeCSS reads it.

Frequently asked questions

What can you use for free in PurgeCSS?

Code and local use under MIT.

What additional costs might arise with PurgeCSS?

Computing resources, self-hosting, and external services are paid for separately if used.

What terms of use matter for PurgeCSS?

MIT for the code; dependencies have separate licenses.

How do you get started with PurgeCSS?

Specify content sources containing used CSS classes. Add exceptions for dynamic classes and compare styles before and after cleanup. Add the workflow to scripts or CI with a clear report.

Why didn't a purgecss ignore rule work in a production build?

The documentation warns that cssnano and other processors may remove CSS comments beforehand. Use a preserved important comment such as /*! purgecss ... */ or adjust processing order. Safelist also supports strings and standard, deep, and greedy regular expressions.

License

MIT for the code; dependencies have separate licenses.

MIT — permissive license

You can use, modify, distribute, and sell the code, including in a closed-source commercial product. When sharing copies or substantial portions of the code, retain the license text and copyright notice. You do not need to open-source your entire project; the author provides no warranties.

License terms

Technologies and topics

  • PurgeCSS
  • build
  • Development

Sources

Other resources