What Is CSS Minification?
CSS minification is the process of removing all unnecessary characters from a CSS file without changing its functionality. This includes comments, spaces, newlines, and indentation. The resulting minified CSS file is smaller in size and loads faster in browsers, which improves page performance โ particularly on mobile connections and for users far from your server.
Well-formatted CSS with comments and consistent indentation is easy to read and maintain during development. The minified version is what gets served to end users in production. Modern build tools like webpack, Vite, and Gulp handle minification automatically in a build pipeline.
How to Use This CSS Minifier
Paste your CSS into the left text area. The minifier processes it in real time and shows the compressed output on the right. The stats bar shows the original size, minified size, and percentage saved. Click Copy to copy the minified CSS to your clipboard.
What This Minifier Does
The minification pipeline runs these transformations in order:
- Remove block comments โ strips
/* ... */comments - Remove line comments โ strips
// ...comments (non-standard but common in SCSS output) - Collapse whitespace โ replaces all runs of whitespace/newlines with a single space
- Remove spaces around punctuation โ removes spaces around
{ } : ; , >characters - Remove trailing semicolons before closing braces โ
;}becomes} - Trim โ removes leading/trailing whitespace
CSS Minification Best Practices
- Always keep the original: Never edit the minified version โ keep your formatted source and re-minify when you make changes.
- Use source maps in development: Browser DevTools can map minified CSS back to original lines using
.mapfiles from build tools. - Combine with server compression: Enable gzip or Brotli on your web server โ minification + compression together reduce CSS sizes by 70โ90%.
- Use a build pipeline for production: For complex projects, use tools like PostCSS/cssnano for advanced optimisations like combining duplicate selectors.
Frequently Asked Questions
What is CSS minification?
Removing unnecessary characters from CSS โ comments, whitespace, newlines โ without changing its behaviour. The minified file is smaller, loads faster, but is not human-readable. Keep the original formatted source for editing.
How much does minification reduce file size?
Typically 20โ40%. Files with extensive comments can see 50%+ reduction. Combined with gzip server compression, the combined reduction can reach 80% of the original size.
Does this handle all CSS features?
It handles standard CSS and compiled preprocessor output. It does not merge duplicate rules or perform shorthand consolidation. For production use, consider cssnano (via PostCSS) for deeper optimisation.
Is minified CSS safe for production?
Yes โ it is functionally identical to the original. Browsers parse minified and formatted CSS the same way. Always test after minification to ensure no edge cases were affected.
What is the difference between minification and compression?
Minification removes characters from the source code before serving. Compression (gzip/Brotli) compresses the bytes during HTTP transfer. Both are complementary โ minify first, then enable server-side compression for maximum savings.