HTML Formatterhtmlformatteronline.com

CSS minifier

Strip comments and whitespace without breaking calc(), data URIs or quoted content. The readout shows exactly what you saved.

Your CSS 0 lines
Minify
Minified 0 lines
Paste CSS on the left, then press the button.

What it removes

Everything a browser does not read: comments, indentation, newlines, the space after every colon and comma, and the final semicolon in each block. On a hand-written stylesheet that is usually 20 to 35 percent of the file.

Source
.card {
  border: 1px solid #dee4ee;
  border-radius: 12px;
  padding: 20px 22px;
}
Minified
.card{border:1px solid #dee4ee;border-radius:12px;padding:20px 22px}

It does not rewrite values. Colours stay in the notation you wrote them in, 0.5em keeps its leading zero, and shorthand is not collapsed. Those transformations save more bytes and carry more risk — they belong in a dedicated build tool like cssnano or Lightning CSS, which have test suites behind them.

Where CSS minification actually pays

CSS is render-blocking. The browser will not paint until it has your stylesheet, which makes it worth more attention than HTML byte-for-byte. That said, the ordering of wins is not what people expect:

ActionTypical effectEffort
Enable gzip or brotli75–85% smallerOne server setting
Remove unused CSSOften 60–90% smallerA build step and some care
Minify20–35% before compression, a few percent afterA build step
Inline critical CSSRemoves one render-blocking requestReal work

If your stylesheet is genuinely slowing the page down, unused rules are almost certainly the bigger problem. Most sites ship a framework and use a fraction of it.

Safe by design

The minifier tracks strings, comments and parentheses the same way the formatter does, so:

  • A semicolon inside url(data:image/svg+xml;base64,...) does not end the declaration.
  • A brace inside content: "}" does not close the block.
  • Spaces inside calc(100% - 2rem) are preserved — remove them and the expression breaks.
  • Spaces inside grid-template-areas strings are preserved.

Those four are where naive regular-expression minifiers fail, and they fail silently.

Doing it in a build

Command line
npx cssnano input.css output.css
PostCSS
module.exports = {
  plugins: {
    autoprefixer: {},
    cssnano: { preset: "default" }
  }
};

Vite, Next.js, Astro and every modern bundler minify CSS in production builds already. Check before you add anything — you may be doing this twice.

This page is for the cases with no build: a single landing page, a snippet going into a CMS field, an email template, or a quick check of how much a file would shrink.

Questions about this tool

Will minifying break my CSS?

It should not. Spaces that carry meaning — inside calc(), inside strings, between compound values like 1px solid red — are preserved. If you do find a case where it breaks something, send the input and it gets fixed.

Does it remove unused CSS?

No. That needs to know which selectors your HTML actually uses, which means analysing your whole site. PurgeCSS and Tailwind's own build do this; a standalone minifier cannot.

Should I minify CSS if my server already uses gzip?

The gain drops to a few percent, but it is free inside a build step, so yes. What you should not do is skip compression because you minified — compression is by far the larger effect of the two.

Can I get my formatted CSS back?

Switch to Format and the structure returns. Comments do not, if you stripped them. Keep your source file in version control and treat the minified version as a build artefact.

Related tools

Learn the why, not just the how

Longer reading on formatting, indentation and minification.