View on GitHub

Uncss

Remove unused styles from CSS

Download this project as a .zip file Download this project as a tar.gz file

UnCSS

Build Status

Remove unused styles from CSS

Installation:

npm install -g uncss

Usage

Within node:

var uncss = require('uncss');

var files   = ['my', 'array', 'of', 'HTML', 'files'],
    options = {
        ignore: ['#added_at_runtime', /test\-[0-9]+/],
        csspath: "../public/css/",
        raw: 'h1 { color: green }',
        stylesheets: ["lib/bootstrap/dist/css/bootstrap.css", "src/public/css/main.css"],
        urls: ["http://localhost:3000/mypage", "..."] //array of urls
        timeout: 1000
    };

uncss(files, options, function (output) {
    console.log(output);
});

/* Look Ma, no options! */
uncss(files, function (output) {
    console.log(output);
});

/* Specifying raw HTML*/
var raw_html = '...'
uncss(raw_html, options, function (output) {
    console.log(output);
});

From the command line:

Usage: uncss [options]

Options:

-h, --help                     output usage information
-V, --version                  output the version number
-i, --ignore <selector, ...>   Do not remove given selectors
-C, --csspath <path>           Relative path where the CSS files are located
-s, --stylesheets <file, ...>  Specify additional stylesheets to process
-r, --raw <string>             Pass in a raw string of CSS
-t, --timeout <milliseconds>   Wait for JS evaluation

At build-time

UnCSS can also be used in conjunction with other javascript build systems, thanks to @addyosmani for creating:

Options in depth:

License

Copyright (c) 2013 Giacomo Martino. See the LICENSE file for license rights and limitations (MIT).

Features planned: