CSS Minifier: Shrink a Stylesheet in Your Browser

Paste a stylesheet and get the compact version at once, with the size before and after. Only comments, spacing and spare semicolons are removed.

TechFreeNo sign-upWorks on phones
––
0Bytes before
0Bytes after
Minified CSS

This tool shortens CSS. It does not check that your CSS is valid and it never changes a color, number, unit or property name.

This tool runs in your browser. Nothing you type is uploaded or saved, and there is nothing to install or sign up for.

What minifying CSS means

A stylesheet written for people is full of things a browser ignores: indentation, blank lines, notes to yourself, a space after every colon. Minifying deletes those extras so the file is smaller while every rule still means exactly the same thing. Smaller files travel faster, which matters most on slow phone connections and on pages with large stylesheets.

This minifier is deliberately cautious. It removes only characters that have no effect and leaves each value as you wrote it. Nothing is uploaded: the work happens in the page you are looking at, so it is fine for homework projects and for code you would not want to send to a server.

Steps to shrink a stylesheet

  1. Paste your code into Your CSS, replacing the sample. The result appears a moment after you stop typing, or press Minify CSS.
  2. Decide whether to leave Keep important comments ticked. It protects comments that begin with /*!, the usual marker for license and copyright notices.
  3. Read the dark panel for the percent saved and the two tiles for Bytes before and Bytes after.
  4. Press Copy minified CSS and save it as a separate file, commonly named with .min.css on the end.
  5. Clear the box empties the input; Reset reloads the sample.

Worked example with the byte count

Paste these three lines:

h1 { color : navy ; }
/* title */
p{margin:0 auto}

The output is one line:

h1{color:navy}p{margin:0 auto}

The input is 50 bytes including its two line breaks, the output is 30, and the panel shows 40% smaller. The comment has gone, the spaces around the braces, colon and semicolon have gone, and so has the semicolon before the closing brace, because the last declaration in a block does not need one. The space in 0 auto stays, since removing it would join two values into nonsense.

The sample that loads with the page is a more realistic case: 306 bytes become 241, a saving of 21.2%. Code that is already compact saves less; a{b:c} comes back unchanged at 0%.

Exactly what is removed and what is kept

RemovedLeft alone
Ordinary commentsComments starting with /*! (while the box is ticked)
Line breaks, tabs and indentationEverything inside quotation marks
Spaces around { } ; ,Everything inside url( )
Spaces around the colon in a declarationSpaces around + and − inside calc( )
Spaces around the child sign in a selectorThe space between two selectors such as .card .hint
The final semicolon in a block, and empty declarationsColors, numbers, units, zeros and !important

The method is a single pass through the text, one character at a time. The minifier tracks whether it is inside a string, a comment, a url() or a pair of parentheses, and whether the current piece is a selector, a declaration or an at-rule such as @media. That context decides whether a space can go. A colon inside a selector, as in a :hover, keeps the space before it because there the space changes the meaning; a colon in color : red does not.

Sizes are counted in bytes of UTF-8, the encoding nearly all web files use. Plain English letters and symbols take one byte each, and accented letters or symbols take two or more.

What this tool will not do

  • It does not validate. A misspelled property or a missing value passes straight through. You get a warning only for two structural problems: braces that do not pair up and a comment that is never closed.
  • It does not rewrite values. #ffffff is not shortened to #fff, 0px is not turned into 0, and duplicate rules are not merged. Build tools that do those things can squeeze out a little more, at the price of touching your code.
  • It does not un-minify. There is no button to turn compact CSS back into indented CSS, so keep your original file.
  • It does not replace server compression. Web servers commonly compress text files as they send them. Minifying and compression work together; one does not make the other pointless.
  • Comments are gone for good. Edit the readable file and minify again each time, instead of editing the minified copy.

Good habits for students and site owners

Keep two files: style.css that you edit and style.min.css that the page loads. In a web design class this is a neat way to see the difference between code for humans and code for machines, and the byte tiles make a quick percentage exercise you can check with the percentage change calculator (50 down to 30 is a 40% drop).

If a minified page suddenly looks wrong, paste the before and after into the diff checker one rule at a time to find the spot, and look first at the warning box above the result. Sizes you still have in pixels can be turned into scalable units with the PX to REM converter, and data files get the same tidy-up treatment in the JSON formatter, which can also compact JSON to one line.

See the rest of the developer and tech tools or return to the full shelf of free online tools.

Frequently asked questions

Is minified CSS the same as the original?

It behaves the same. Only comments, line breaks, spare spaces and unneeded semicolons are removed, so the browser reads identical rules from a smaller file.

How much smaller does CSS get when minified?

It depends on how the file was written. The short example on this page drops from 50 to 30 bytes, which is 40 percent, and the built-in sample saves 21.2 percent. Heavily commented and indented files save the most.

Does this minifier upload my CSS?

No. The minifying runs in your own browser and the text is not sent or stored anywhere.

Why are some comments kept?

Comments that begin with a slash, a star and an exclamation mark are a common way to mark license or copyright notices that must stay in the file. Untick the box if you want those removed too.

Can I turn minified CSS back into readable CSS?

Not with this tool, and deleted comments cannot be recovered by any tool. Keep the readable original and treat the minified file as a copy made from it.

Related tools

Browse all free tools →