cssnano is a modular CSS compression tool on the PostCSS stack. It shrinks stylesheets for production while aiming to keep rendering the same as the original CSS.
Overview
cssnano runs a pipeline of focused optimisations on CSS rather than only trimming whitespace. Presets let you choose how aggressive the transforms are: the default preset applies safe changes, while an advanced preset enables stricter tricks only when your site meets the documented requirements.
Documented optimisation types include compressing colors, removing comments, discarding overridden at-rules, normalising unicode-range descriptors, and simplifying gradient parameters. Where relevant, transforms can respect Browserslist so output differs based on the browsers you support.
cssnano can be wired into bundlers and build tools through published installation guides and exposes many individual optimisation plugins. Under semantic versioning, a minified stylesheet should render like the unminified source; cssnano should neither break working CSS nor repair broken CSS, which matters when only production builds are minified.
An online playground lets you try cssnano without a local setup. The implementation is modular plugins composed through PostCSS's plugin architecture.
Key features
- PostCSS plugin architecture
- Default and advanced presets
- Browserslist-aware transforms
- Color and comment compression
- Duplicate rule cleanup
- Gradient parameter simplification
- Unicode-range normalization
- Online try-it interface
Use cases
- Production CSS bundle size reduction
- Pipeline integration via PostCSS
- Safe default minification preset
- Targeted aggressive preset when eligible
- Preserve visual output after minify