A well-tested, fast and efficient CSS minifier for Node.js and browsers. Version 5.3.3 (stable) is released with patch updates over v5.3 (latest major). Clean-css outperforms many alternatives (cssnano, csso) in benchmarks, offering fine-grained optimization levels (0-2), compatibility modes (IE, standards), and source map support. It uses a highly modular plugin system and supports CLI, JavaScript API, and streaming. Engines require Node >= 10.0.
npm install clean-cssNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Basic usage: instantiate CleanCSS with options, call minify() on a CSS string, and log the minified output.
Use dynamic import or ensure package is CJS-compatible. For v5, CommonJS require still works, but future versions may drop it.
Check output.styles instead of output.minified; errors in output.errors array.
Set options.returnPromise = true and await the call.
Use level 1's variableValueOptimizers option to enable variable optimization.
Set options.level[2].mergeMedia = true to restore old behavior.
Use Level 2 'restructureRules' or 'mergeSemantically' options (check docs).
Run 'npm install clean-css' and use 'require('clean-css')' or 'import CleanCSS from 'clean-css''.Use 'import CleanCSS from 'clean-css'' or CommonJS require.
Access 'output.styles' instead of 'output.minified'.
Call minify on a valid CSS string; check output.errors for details.