PurgeCSSPurgeCSS
API Reference
  • English
  • Français
GitHub
API Reference
  • English
  • Français
GitHub
  • PurgeCSS

    • About PurgeCSS
    • Getting Started
    • Configuration
    • Command Line Interface
    • Programmatic API
    • Safelisting
    • Extractors
  • Plugins

    • PostCSS
    • Webpack
    • Gulp
    • Grunt
    • Gatsby
  • Guides

    • Vue
    • React
    • Next.js
    • Nuxt.js
    • Razzle
    • WordPress
    • Hugo
  • Comparison
  • Common Questions

    • How to use with CSS modules
    • How to use with Ant Design

CLI

PurgeCSS is available via a Command Line Interface. You can use the CLI by itself or with a configuration file.

Installation

You can either install PurgeCSS as a dev dependency and use the CLI with npx or you can also install PurgeCSS globally:

npm i -g purgecss

Usage

To see the available options for the CLI: purgecss --help

Usage: purgecss --css <css...> --content <content...> [options]

Remove unused css selectors

Options:
  -V, --version                        output the version number
  -con, --content <files...>           glob of content files
  -css, --css <files...>               glob of css files
  -c, --config <path>                  path to the configuration file
  -o, --output <path>                  file path directory to write purged css files to
  -font, --font-face                   option to remove unused font-faces
  -keyframes, --keyframes              option to remove unused keyframes
  -v, --variables                      option to remove unused variables
  -rejected, --rejected                option to output rejected selectors
  -rejected-css, --rejected-css        option to output rejected css
  -s, --safelist <list...>             list of classes that should not be removed
  -b, --blocklist <list...>            list of selectors that should be removed
  -k, --skippedContentGlobs <list...>  list of glob patterns for folders/files that should not be scanned
  -p, --preserve-paths                 preserve folder hierarchy in the output
  -h, --help                           display help for command

The options available through the CLI are similar to the ones available with a configuration file. You can also use the CLI with a configuration file.

--css

purgecss --css css/app.css css/palette.css --content src/index.html

--content

You can specify content that should be analyzed by PurgeCSS with an array of filenames or globs. These files can be HTML, Pug, Blade, etc.

purgecss --css css/app.css --content src/index.html src/**/*.js

--config

You can use the CLI with a configuration file. Use --config or -c with the path to the config file.

purgecss --config ./purgecss.config.js

--output

By default, the CLI outputs the result in the console. If you wish to return the CSS as files, specify the directory to write the purified CSS files to.

purgecss --css css/app.css --content src/index.html "src/**/*.js" --output build/css/

--preserve-paths

By default, the CLI flattens the folder hierarchy and outputs all CSS files to the same directory. If you want to preserve the original folder structure in the output, use the --preserve-paths flag.

purgecss --css src/**/*.css --content src/index.html --output build/ --preserve-paths

For example, if your CSS files are located at:

  • src/styles/main.css
  • src/components/button.css

Without --preserve-paths, both files would be written to build/main.css and build/button.css.

With --preserve-paths, the files would be written to:

  • build/src/styles/main.css
  • build/src/components/button.css

--safelist

If you wish to prevent PurgeCSS from removing a specific CSS selector, you can add it to the safelist.

purgecss --css css/app.css --content src/index.html --safelist classnameToSafelist
Edit this page
Last Updated: 1/24/26, 2:11 PM
Contributors: Ffloriel, Jérémy Benoist, Patrick Hill, Kevin Ramharak, Floriel
Prev
Configuration
Next
Programmatic API