This project is not covered by Drupal’s security advisory policy.

This modules is no longer being maintained.

Consider migrating to Advanced CSS/JS Aggregation

This module automatically runs CSSTidy using the highest compression template when CSS optimization is enabled in the Performance settings. It can also be configured to make the stylesheet readable using minimal linebreaks while still significantly compressing it. The default Drupal optimization removes whitespace around separators and comments that are not CSS hacks. This leaves much to be desired, especially considering it doesn't effectively remove all unnecessary whitespace is some instances. CSSTidy improves upon this by optimizing the stylesheet in the following ways:

  • Colors like black or rgb(0,0,0) are converted short-hand hex-codes like #000 when possible. Some hex-codes are replaced by their color names if they are shorter (#f00 becomes red)
  • a{property:x;property:y;} becomes a{property:y;} (all duplicate properties are merged)
  • margin:1px 1px 1px 1px; becomes margin:1px;
  • margin:0px; becomes margin:0;
  • a{margin-top:10px; margin-bottom:10px; margin-left:10px; margin-right:10px;} becomes a{margin:10px;}
  • margin:010.0px; becomes margin:10px;
  • All unnecessary whitespace is removed
  • All background: properties are merged
  • All comments are removed
  • The last semicolon in every block is removed
  • Missing semicolons are added, incorrect newlines in strings are fixed, missing units are added, bad colors (and color names) are fixed
  • property:value ! important; becomes property:value !important;

Why optimize?

If you optimize your CSS code you have faster loading pages and lower traffic costs. So both you and your visitors benefit from an optimization. Be sure to also try out the following modules which are compatible with CSSTidy:

  • CSS Gzip or Boost - Compress .css files using gzip
  • CSS Embedded Images - Reduce http requests by embedding images in stylesheet.
  • CDN or Parallel - Changes the source of css files so users can download them faster.

Known Issues

Pressflow

CSSTidy is not currently compatible with Pressflow.

See Pressflow bug: #597718: file.inc function file_create_url() not correct

Hacks that work

The following is a list of all CSS hacks that will not be modified by CSSTidy. In general, you shouldn't use CSS hacks, but if you need them and want to use CSSTidy you should use one of the following hacks:

Special Thanks to...

Project information

Releases