CSS Minifier and alphabetiser
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.


What is it?

CSSMin takes your CSS file and strips out everything that’s not needed — spaces, extra semicolons, redundant units, and so on. That’s great, but there are loads of programs that do that. A shell script could do that! So what makes CSSMin different?

When you deliver content over the web, best practice is to deliver it gzipped. CSSMin takes your CSS file, and optimises it for gzip compression. This means that there’s a smaller payload delivered over the wire, which results in a faster experience for your users. It does this optimisation by ensuring that the properties inside your selectors are ordered consistently (alphabetically) and in lower case. That way, the gzip algorithm can work at its best.

What this means in practice is that your gzipped CSSMin-ed files are significantly smaller than plain gzipped CSS, and noticeably smaller than files that have been compressed by other means (say, YUI).

What does it do?

  • Replaces font-weight values like 'bold' with their numeric counterparts;
  • Strips quotes wherever possible;
  • Changes as much of the contents to lowercase as possible;
  • Strips all comments from the source;
  • Removes unnecessary whitespace; and, most importantly,
  • Reorders the properties within your selectors alphabetically.

What does it support?

Just about everything! Nested properties benefit from compression (for example, -webkit-keyframes), whilst retaining the appropriate order. Prefixed selectors are moved to the top of the block, so that their non-prefixed counterparts will override them when the browser supports them. Most CSS hacks won't get stripped, but some involving comments might break.


  1. Compile the library with ant:

     # ant
  2. Run your CSS through it:

     # java -jar CSSMin.jar [input] [output]
  3. Profit!


These are the results of compressing the main CSS file for one of the webapps I develop at work. Note that many of these compressors only offer an online service, which means that they can't easily be used as part of your general build process.

  Original size (bytes) Gzipped size (bytes)
Plain 81938 12291
YUI 64434 10198
LotteryPost 63609 10165
CSS Drive 69275 10795
CSSMin 63791 9896


CSSMin was originally written, and is maintained by, Barry van Oudtshoorn.



CSSMin is licensed under the BSD License. See LICENSE for details.