Sean L. YoungStudio tools
Step 4 · Check & launch

CSS Minifier

Shrink a stylesheet for a faster site: comments and spaces come out, and colours and numbers are written the short way. Or switch to Tidy to turn squashed or messy CSS into neat, readable rules. Either way, the browser reads both versions and checks they mean exactly the same.

What it's for

The CSS Minifier works both ways:

  • Smaller: squeezes a finished stylesheet down for the live site. Every byte saved is one less for visitors to download, which matters most on phones.
  • Tidy: does the opposite. It spreads squashed or messy CSS out into neat, indented rules you can read and edit, such as a minified file from a theme, or CSS someone else wrote.

Whichever you choose, the browser itself reads the original and the result and compares them, so you can be sure nothing changed except the layout of the text.

Quick start

  1. Paste the CSS into the left box, drop a .css file on it, or click Open file….
  2. Choose Smaller or Tidy at the top.
  3. Check the two boxes under the result: Reads cleanly and Same meaning as the original.
  4. Copy or download the result.

Click Try an example to see it work on a sample stylesheet.

Making it smaller

With Smaller chosen, comments, line breaks and extra spaces are removed. The options:

  • Shorten colours and numbers: writes values the shortest way that means the same, such as #ffffff as #fff, 0.50 as .5, and 0px as 0.
  • Keep /*! licence */ comments: comments that start with /*! usually hold a licence that must stay with the code, such as for a font or library. Leave this ticked.
  • Remove empty rules: drops rules with nothing inside them.

The numbers under the result show the size before and after, and how much smaller it is. Where the browser supports it, you'll also see the compressed (gzip) sizes: most web servers compress CSS before sending it, so that's closer to what visitors actually download.

Keep the original

Always keep the readable version for editing, and upload the small one. A common way is style.css for editing and style.min.css on the site, which is the name the download uses.

Tidying

With Tidy chosen, every rule goes on its own lines, with one setting per line, neatly indented. Choose the indent (2 spaces, 4 spaces or a tab), and whether to keep comments.

The download is named style.css.

The two checks

Reads cleanly

The first box checks the CSS you pasted. If it finds a problem, it lists it with its line, and you can click it to jump there. Typical problems:

  • a { that's never closed with }
  • a { with no selector in front of it
  • a comment never closed with */, or quoted text never closed.

The result is still made from whatever can be read, but fix the problems in the original first.

Same meaning as the original

The second box is the safety net. The browser reads both the original and the result as real stylesheets, and compares every rule and setting. If they match, it says Same meaning as the original.

If it ever says The browser reads the result differently, it shows exactly where. Use the original CSS instead, and please pass the example on so it can be fixed.

Using the result

  • Copy copies the result.
  • Download saves it as style.min.css (Smaller) or style.css (Tidy).
  • Use as input moves the result into the left box, so you can work on it further. Ctrl+Z puts the old version back.

The left box works like the code box in the Code Sandbox: coloured code, line numbers, Ctrl+/ to comment out a line, Tab to indent, and Esc then Tab to leave the box. Your last CSS is kept in this browser until you click Clear.

Questions

How much smaller will it get?

Usually 20 to 40 percent for a hand-written stylesheet with comments and generous spacing. A stylesheet that's already compact shrinks less.

Does it remove CSS the site doesn't use?

No. It only changes how the CSS is written, never what it does, so it can't break a page. Removing unused rules needs a tool that looks at every page of the site.

Can I minify JavaScript or HTML too?

No, just CSS.

Is my CSS sent anywhere?

No. Nothing you paste leaves this browser.