Back to All Tools

CSS Minifier

Minify CSS to make the file smaller, or beautify it to make it easy to read.

100% Private — Your data never leaves your browser. Everything runs locally on your device.

What the Minify button does

The minifier reads your CSS one piece at a time, a bit like a browser does. It knows where quoted text, comments, url() values, brackets and selectors start and end. Then it makes these changes:

  1. It removes comments. Comments that start with /*! stay, because that is how license notes are marked.
  2. It turns each run of spaces, tabs and line breaks into one space.
  3. It removes that space where it has no meaning. For example, next to { } ; ,, after the colon in color: red, and around > + ~ between selectors.
  4. It removes the last semicolon before each }.

Here is a real example. This input is 237 characters long:

/* Buttons */
.btn {
  display: inline-block;
  padding: 0.5rem 1rem;
  border: 1px solid #ccc;
  border-radius: 4px;
}

.btn:hover,
.btn:focus {
  background-color: #f0f0f0;
}

@media (max-width: 600px) {
  .btn {
    width: 100%;
  }
}

The tool returns one line of 175 characters. The line under the buttons shows 26.2% smaller.

.btn{display:inline-block;padding:0.5rem 1rem;border:1px solid #ccc;border-radius:4px}.btn:hover,.btn:focus{background-color:#f0f0f0}@media (max-width:600px){.btn{width:100%}}

Spaces that separate values stay, as in 1px solid #ccc. The space after @media stays too.

Spaces and text it keeps on purpose

Some spaces change what CSS means. Removing them would break your page, so the tool keeps them. Text inside quotes is copied exactly. We ran each input below through the tool:

InputOutputWhy
width: calc(100% + 2rem);width:calc(100% + 2rem)Inside calc(), min(), max() and clamp(), a + or - needs a space on both sides. Without it the browser ignores the line.
.card :hover { … }.card :hover{…}This space means "any hovered element inside .card". Without it, the selector would mean .card itself. The same goes for & :hover in nested CSS.
content: "/* hi */";content:"/* hi */"It looks like a comment, but it is text inside quotes.
content: " a b ";content:" a b "Spaces inside quotes show on screen, so they stay.
a[title="a , b"]a[title="a , b"]The quoted value must match the HTML exactly.
content: ";}";content:";}"A ; or } inside quotes does not end the rule.
url(data:image/png;base64,…)(unchanged)Everything inside url() is copied as it is.
/*! MIT License *//*! MIT License */License comments stay at their place in the file.

Spaces that do not change the meaning still go. For example, ul > li + li becomes ul>li+li, and color: red !important becomes color:red!important.

We tested these cases, plus this site's own stylesheet, with a separate CSS parser. The parser read the same rules and values before and after minifying.

What it does not do

A full CSS minifier in a build tool does more than remove spaces and comments. This tool does not:

Vendor prefixes such as -webkit- are not added or removed. They are copied like any other text.

The Beautify button

Beautify does the opposite job. It turns a minified file back into something you can read:

Beautify on the minified example above gives this:

.btn {
  display: inline-block;
  padding: 0.5rem 1rem;
  border: 1px solid #ccc;
  border-radius: 4px;
}

.btn:hover,
.btn:focus {
  background-color: #f0f0f0;
}

@media (max-width: 600px) {
  .btn {
    width: 100%;
  }
}

Comments in your input stay when you beautify. But comments that Minify already removed cannot come back.

How much does minifying really save?

The line under the buttons counts characters, not bytes. For CSS written in plain English letters, the two numbers are the same. Letters such as é or emoji inside content take more than one byte.

Most web servers also compress CSS with gzip or Brotli before they send it. Compression already shrinks repeated spaces well. So the saving on the network is smaller than the percentage suggests. As a test, we ran this site's own stylesheet through the tool at the time of writing. It went from 31,839 to 25,309 characters, which is 20.5% smaller. After gzip, the file went from 6,931 to 5,652 bytes. That is about 1.3 KB less to download.

When to use this tool

This tool fits small, one-off jobs. For example, a snippet for an HTML email, a <style> block inside a page, or a quick look at how much whitespace a file has. Beautify is handy when you need to read a minified file from a live site.

For a production website, use the CSS minifier in your build tool or bundler. Those tools also shorten values and merge rules, so the file gets a bit smaller. They run every time you build, so you never forget a step. Keep your readable file as the source, and treat the minified file as output you can create again at any time.

Frequently Asked Questions

Can minifying with this tool break my CSS?

It is built not to. It knows about quoted text, comments, url() values, brackets and selectors, and it keeps every space that matters, such as the ones in calc(100% + 2rem) and .card :hover. We checked the output with a separate CSS parser on many tricky cases and on this site's own stylesheet. One limit: if your CSS already has an error, such as a missing brace, the tool does not fix it or warn you.

Does it keep the spaces in calc()?

Yes. calc(100% + 2rem) stays calc(100% + 2rem). CSS needs a space on both sides of + and - inside calc(), min(), max() and clamp(), so the tool never removes those. It only removes spaces next to brackets and commas, so calc( 1px + 2px ) becomes calc(1px + 2px).

Does it keep license comments that start with /*!?

Yes. Comments that start with /*! stay in the output exactly as you wrote them. All other comments are removed.

Is the percentage the real download saving?

Not exactly. The tool compares character counts before any server compression. Most servers send CSS with gzip or Brotli, which already shrinks whitespace. In our test on this site's stylesheet, 20.5% fewer characters meant about 1.3 KB less to download after gzip.

Does Beautify give me back my original file?

Not exactly. Beautify puts one declaration on each line and indents by nesting, including rules inside @media. It never breaks a line inside quotes, url() or brackets. But comments that Minify removed are gone, and your own blank lines and spacing style are not restored.

Is my CSS sent to a server?

No. Both buttons run in your browser. Your CSS is not uploaded anywhere.