CSS Minifier

Strip comments and spaces from CSS into one line, or expand packed CSS with indentation.

Indent
Input
Output

Minify removes comments and needless whitespace to shrink a stylesheet; Beautify expands one-line CSS so it is readable. Both are regex replacements, so they are fast, and the code never leaves the page.

Sample CSS loads a stylesheet with 6 comments and 11 rules. These are the stats after each button.

ButtonOriginalResultSaved
Minify1,130 bytes742 bytes-34%
Beautify (2 spaces)1,130 bytes898 bytes-21%

Minify does about four things: removes comments, removes spaces around { } : ;, removes spaces after commas, and drops the last semicolon in a block. .header { margin: 0; } becomes .header{margin:0}. It does not shorten #ffffff to #fff or merge rules; a build tool such as cssnano or esbuild does that.

A selector that changes meaning

.card :first-child loses the space before the colon and becomes .card:first-child, which changes the meaning from "first child inside a card" to "a card that is a first child". Rewrite the original as .card *:first-child before minifying. Spaces inside quotes are collapsed too, so content: "a ; b" turns into "a;b", and a /*! ... */ license comment is removed. Spaces in calc(100% - 20px) are kept.

Beautify minifies first and then adds line breaks, so deleted comments do not return. SCSS features such as // comments, variables and nesting are not CSS; compile first. To shrink markup as well, pair it with the HTML minifier.