CSS Compactor – Reduces CSS File Size

This is a script I wrote back 2006 that reduces the file size for CSS files by removing unnecessary whitespace and comments. It’s also capable of taking such compacted CSS file, and re-indent it to make it readable. For example it would take the following CSS:

/* sample css */
* {
    margin: 0px;
    padding: 0px;
}

/* define style for the logo */
#header .logo {
    float: left;
    /* another comment */
}

and turn it into:

*{ margin:0px; padding:0px;}#header .logo{ float:left;}

which is an equivalent but much shorter CSS code. It can also reindent it back to:

*{
	 margin: 0px;
	 padding: 0px;
}
#header .logo{
	 float: left;
}


As I said the script is very old, and was written around the time I learned how to use python, so it is far from perfect. But despite that, it does what it was written for and it’s useful, so I deemed it worth to release it. You can download it from here: csscompactor-0.4.tar.gz.

The code is released under the GPL, so feel free to modify it. If there will be enough interest in it, I’ll probably re-write so it would have prettier and more efficient code.

2 thoughts on “CSS Compactor – Reduces CSS File Size”

  1. Thk,

    Thank you, very useful utility. It work well for unindent!

    PiF

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.