Command-Line Interface (CLI)

UnCSS provides a powerful command-line interface for quick usage from your terminal. To use it, you must first install it globally.

Basic Usage

The simplest way to use the CLI is to pass it a list of HTML files or URLs. By default, it prints the cleaned CSS to standard output.

# Process a local HTML file
uncss index.html

# Process a remote URL
uncss https://getbootstrap.com/docs/3.3/examples/jumbotron/

# Process multiple files using glob patterns
uncss pages/**/*.html

Writing to a File

You can redirect the output to a file using the > operator or the built-in --output (-o) flag.

# Using redirection
uncss index.html > clean.css

# Using the --output flag
uncss index.html --output clean.css

Reading from Stdin

If no files are specified, uncss will read HTML from standard input. This is useful for piping content from other tools.

cat index.html | uncss --stylesheets style.css > clean.css

CLI Options

All configuration options can be passed as flags to the uncss command. You can view all available options by running uncss --help.

Flag Description
-h, --help Output usage information.
-V, --version Output the version number.
-i, --ignore <selector, ...> Do not remove given selectors (comma-separated).
-m, --media <media_query, ...> Process additional media queries (comma-separated).
-C, --csspath <path> Relative path where the CSS files are located.
-s, --stylesheets <file, ...> Specify additional stylesheets to process.
-S, --ignoreSheets <selector, ...> Do not include specified stylesheets.
-r, --raw <string> Pass in a raw string of CSS.
-t, --timeout <milliseconds> Wait for JS evaluation.
-H, --htmlroot <folder> Absolute paths' root location for stylesheets.
-u, --uncssrc <file> Load options from a JSON configuration file.
-n, --noBanner Disable the informational banner in the output.
-a, --userAgent <string> Use a custom user agent string.
-I, --inject <file> Path to a JavaScript file to be executed.
-o, --output <file> Path to write the resulting CSS to.

Examples

Ignoring Selectors:

Use the --ignore flag to prevent specific selectors from being removed.

uncss index.html --ignore ".fade,.in,#js-modal"

Specifying Stylesheets:

Override the stylesheets found in the HTML and process a specific set of files.

uncss index.html --stylesheets "/css/main.css,css/vendor.css"

Using a Configuration File:

For complex projects, it's easier to manage options in a .uncssrc file.

uncss --uncssrc ./.uncssrc-config.json index.html

See the Configuration guide for details on the .uncssrc file format.