Command-Line Interface (CLI) Reference

PurifyCSS provides a command-line interface (CLI) for quick and easy usage from your terminal or scripts.

Installation

To use the CLI, you must install the package globally:

npm install -g purify-css

Usage

The basic syntax for the purifycss command is:

purifycss <css> <content> [options]
  • <css>: One or more paths to your CSS files.
  • <content>: One or more paths to your content files (HTML, JS, etc.).
  • [options]: Flags to control the output and behavior.

Note: The CLI currently does not support glob patterns. You must provide explicit file paths.

Options

Here are the available command-line options:

Flag Alias Description Type Default
--min -m Minify the final CSS output. boolean false
--out -o Filepath to write the purified CSS to. If omitted, the output is printed to standard output. string stdout
--info -i Log information on how much CSS was removed. boolean false
--rejected -r Log the specific CSS selectors that were removed. boolean false
--whitelist -w A space-separated list of selectors to whitelist. array []
--help -h Show the help message. boolean -
--version -v Show the version number. boolean -

Examples

Basic Purification

Purify main.css based on the content of index.html and print the result to the console.

purifycss src/css/main.css src/index.html

Purify, Minify, and Save to File

Combine multiple CSS and content files, minify the result, get info about the reduction, and save it to a new file.

purifycss src/css/main.css src/css/bootstrap.css src/js/main.js --min --info --out dist/styles.purified.css

This command will:

  1. Concatenate main.css and bootstrap.css.
  2. Scan main.js for used selectors.
  3. Remove unused selectors from the combined CSS.
  4. Minify the result.
  5. Print reduction info to the console.
  6. Save the final CSS to dist/styles.purified.css.

Using a Whitelist

Purify CSS but ensure that selectors containing modal or the class js-active are never removed.

purifycss main.css app.js --whitelist "*modal*" js-active --out purified.css