Tool for finding out which CSS selectors you're NOT using.
Switch branches/tags
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.
docs Discovered empirically. (#56) Jun 6, 2018
example optimizations to rely less on CSSSelector Jun 8, 2016
mincss cli supports --version Feb 8, 2018
proxy Full Python 3 support Jan 18, 2014
tests split on : better, fixes #51 (#52) Jan 3, 2018
.travis.yml travis test in Python 3.5 too Jul 10, 2017
LICENSE Correction of name Apr 7, 2015 Full Python 3 support Jan 18, 2014
README.rst version 0.11.4 Jan 3, 2018
requirements.txt Added cssselect to requirements.txt. Jan 22, 2013 use utf-8 to codec write outputs (#50) Nov 21, 2017 travis test in Python 3.5 too Jul 10, 2017



Build status

Clears the junk out of your CSS by finding out which selectors are actually not used in your HTML.

By Peter Bengtsson, 2012-2018

Tested in Python 2.7, 3.3, 3.4 and 3.5


$ mincss


From pip:

$ pip install mincss


With the onslaught of Twitter Bootstrap upon the world it's very tempting to just download their whole fat 80+Kb CSS and serve it up even though you're not using half of the HTML that it styles.

There's also the case of websites that have changed over time but without the CSS getting the same amount of love refactoring. Then it's very likely that you get CSS selectors that you're no longer or never using.

This tool can help you get started reducing all those selectors that you're not using.

Whitespace compression?

No, that's a separate concern. This tool works independent of whitespace compression/optimization.

For example, if you have a build step or a runtime step that converts all your CSS files into one (concatenation) and trims away all the excess whitespace (compression) then the output CSS can still contain selectors that are never actually used.

What about AJAX?

If you have a script that creates DOM elements in some sort of window.onload event then mincss will not be able to know this because at the moment mincss is entirely static.

So what is a web developer to do? Simple, use /* no mincss */ like this for example:

.logged-in-info {
    /* no mincss */
    color: pink;

That tells mincss to ignore the whole block and all its selectors.

Ignore CSS

By default, mincss will find all <link rel="stylesheet" ... and <style...> tags and process them. If you have a link or an inline tag that you don't want mincss to even notice, simply add this attribute to the tag:


Leave CSS as is

One technique to have a specific CSS selector be ignored by mincss is to put in a comment like /* no mincss */ inside the CSS selectors block.

Another way is to leave the whole stylesheet as is. The advantage of doing this is if you have a link or style tag that you want mincss to ignore but still find and include in the parsed result.