cssfix is a lightweight Python utility that cleans and optimizes your CSS code.
It removes comments ποΈ, merges duplicate selectors π§©, and outputs a compact result β‘.
Perfect for small projects, automation, or integrating into build tools.
- π§½ Removes all CSS comments
- π Merges repeated selectors (e.g.
.class1 {}multiple times) - π§ Consolidates CSS properties without duplicates
- π₯ Takes raw CSS string as input
- π€ Returns optimized CSS string output immediately on instantiation
- π Pure Python - no dependencies
From PyPI:
pip install cssfixfrom cssfix import css
css_text = """
/* This is a comment */
.box {
color: red;
}
.box {
background: blue;
}
"""
optimized_css = css(css_text)
print(optimized_css).box{color:red;background:blue;}class css(css_text: str)Creates a new instance of the CSS optimizer and immediately returns optimized CSS string.
css_text:strβ Raw CSS code to optimize
strβ Optimized, minified CSS with merged selectors and no comments