# 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
1

# Usage

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

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

Options:
  -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
  -rejected, --rejected    option to output rejected selectors
  -s, --safelist <list>   list of classes that should not be removed
  -h, --help               display help for command
1
2
3
4
5
6
7
8
9
10
11
12

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
1

# --content

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

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

# --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
1

# --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/
1

# --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
1