CSS Compressor

0.9.5 · maintenance · verified Sun Apr 12

csscompressor is a Python port of the YUI CSS Compressor, designed to minify CSS code by removing unnecessary whitespace, comments, and optimizing various CSS properties. It aims to be an almost exact port, passing all original YUI unittests. The current version, 0.9.5, was last released on November 26, 2017, indicating an infrequent release cadence.

Warnings

Install

Imports

Quickstart

Compress a CSS string by importing the `compress` function and passing the raw CSS code to it.

from csscompressor import compress

css_input = '''
your css {
  /* a comment */
  content: "!";
  margin-left: 0px;
  color: #AABBCC;
}
'''

compressed_css = compress(css_input)
print(compressed_css)
# Expected output: 'your css{content:"!";margin-left:0;color:#ABC}'

view raw JSON →