Skip to main content
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

Example

$ mincss https://github.com

Installation

From pip:

$ pip install mincss

Why?

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:

data-mincss="ignore"

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.

Release files for mincss 0.11.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mincss 0.11.6
File Size Uploaded
mincss-0.11.6.tar.gz 13.9 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for mincss 0.11.6
File Interpreter ABI Platform
mincss-0.11.6-py3-none-any.whl Python 3 none any Details
mincss-0.11.6-py2-none-any.whl Python 2 none any Details

Total release size: 44.3 kB

Release files / mincss-0.11.6.tar.gz

Download URL mincss-0.11.6.tar.gz
Size 13.9 kB
Tags Source
SHA-256 checksum
How to use checksums
376f81f875ae07fe21ececdabfd77738630b25eb318276dbb85e1b7c98b97cd9
BLAKE2b-256 checksum
How to use checksums
29d270811e37df3ae547fe0eb83b88cb28a1f0a01a9dcf7df1ccd51c07d0e447
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / mincss-0.11.6-py3-none-any.whl

Download URL mincss-0.11.6-py3-none-any.whl
Size 15.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8da263ff5454bc4c8065f92ed01cc5be9cf9cc99cbc652db6a10bad84eb63e23
BLAKE2b-256 checksum
How to use checksums
8d3112976bed10e85a3a93551b5d06b6b39cd788942292a37d723f0ca7288a9d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / mincss-0.11.6-py2-none-any.whl

Download URL mincss-0.11.6-py2-none-any.whl
Size 15.2 kB
Tags Python 2
SHA-256 checksum
How to use checksums
cb6633962381646b7f53a0191318d90fec4c667efea2909cf6749d95c7aae1ec
BLAKE2b-256 checksum
How to use checksums
7fc39871989dd42b7f217bb62e812daa3c683bfecc28e373afcc59c0ddfe25cc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.11.6 This release

3 release files

0.11.5

3 release files

0.11.3

3 release files

0.11.1

3 release files

0.11.0

3 release files

0.10.0

3 release files

0.9.0

3 release files

0.8.6

3 release files

0.8.5

3 release files

0.8.4

2 release files

0.8.3

3 release files

0.8.2

2 release files

0.8.1

2 release files

0.8.0

1 release file

0.7.0

1 release file

0.6.1

1 release file

0.6.0

1 release file

0.5.0

1 release file

0.4.1

1 release file

0.4

1 release file

0.3

1 release file

0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page