Skip to main content

CSS Minifier — Shrink Stylesheets Safely

Paste your stylesheet to minify CSS: comments and unnecessary whitespace are removed without touching string values. Switch to Beautify to make minified CSS readable again; everything runs in your browser.

Features

  • Minify CSS: comments removed, whitespace collapsed
  • Quoted strings stay untouched, last semicolon dropped
  • Beautify minified CSS again with one click
  • Beautify indentation: 2 spaces, 4 spaces or tab
  • Auto-format while typing, copy or download as .css
  • Runs entirely in your browser, nothing is uploaded

What CSS Minification Saves

Stylesheets are written for people: indentation, line breaks, blank lines between rules and comments that explain why a workaround exists. The browser needs none of it. Minifying removes those characters, so the file gets smaller and downloads faster while the page looks exactly the same.

How much you save depends on how the CSS was written. Well-commented, generously indented code often loses a quarter or more of its size, as in the example below; code that is already compact gains little. Minification works together with gzip or Brotli on the server, not instead of it: compression shrinks repeated patterns, minification removes bytes before they are compressed at all. Use both.

How This Minifier Works

The minifier reads your stylesheet in order and tells comments, quoted strings and the CSS between them apart. That lets it remove a lot without changing what the CSS means:

  • comments /* … */ are removed
  • line breaks, tabs and repeated spaces collapse; spaces around { } ; , > ~, after : and ( and before ) disappear
  • the last semicolon in a block is dropped: body { color: red; } becomes body{color:red}
  • quoted strings are copied unchanged, so content: "x , y ; { z }" keeps every character
  • the spaces calc() needs around + and - stay, so calc(100% - 2rem) remains valid

Nothing is renamed, merged or shortened: colours such as #ffffff, units like 0px and duplicate rules stay as you wrote them. That makes the tool a good fit for quick size savings, inline <style> snippets and CSS you paste into a CMS. For maximum compression in production builds, a build-step minifier such as Lightning CSS, cssnano or esbuild goes further.

Example: Minify and Beautify Again

This stylesheet has a comment, a selector list and indentation (121 characters):

/* Buttons */
.btn,
.btn-primary {
  padding: 8px 16px;
  color: #fff;
}

.nav > a:hover {
  width: calc(100% - 2rem);
}

Minified, it becomes a single line of 83 characters:

.btn,.btn-primary{padding:8px 16px;color:#fff}.nav>a:hover{width:calc(100% - 2rem)}

To read minified CSS, switch the mode to Beautify. Every rule and declaration gets its own line, indented with the width you choose (here 2 spaces). Neither the comment nor the spaces after colons and the last semicolon come back, so the result is readable but not identical to your original:

.btn, .btn-primary {
  padding:8px 16px;
  color:#fff
}
.nav>a:hover {
  width:calc(100% - 2rem)
}

Tips Before You Ship

  • Keep the original. Edit the readable file and minify a copy. This tool does not create source maps; build tools can write a .map file so that DevTools shows your original lines instead of one long line.
  • License comments disappear too. Comments starting with /*! are removed like any other. If a license requires the notice, add it back by hand.
  • Space before a colon. If you write color : #fff, the space before the colon stays (a{color :#fff}), because removing it would break selectors such as div :first-child. Write declarations without that space to save the byte.

Useful Resources

MDN: Minification Short definition of minification and what it removes from code
MDN: Compression in HTTP How gzip and Brotli compression work alongside minification
Chrome for Developers: Minify CSS Why Lighthouse flags unminified CSS and how to fix it in your build
Lightning CSS Fast build-step CSS minifier and transformer for production builds
W3C: CSS Syntax Module Level 3 The official rules for how CSS is tokenized, including comments and whitespace