Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

uncss

Package Overview
Dependencies
Maintainers
1
Versions
60
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

uncss

Remove unused CSS styles

  • 0.7.8
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
70K
decreased by-6.02%
Maintainers
1
Weekly downloads
 
Created
Source

UnCSS

Build Status Coverage Status Dependency Status devDependency Status

UnCSS is a tool that removes unused CSS from your stylesheets. It works across multiple files and supports Javascript-injected CSS.

Installation:

npm install -g uncss

Usage

Within Node.js:

var uncss = require('uncss');

var files   = ['my', 'array', 'of', 'HTML', 'files'],
    options = {
        ignore       : ['#added_at_runtime', /test\-[0-9]+/],
        media        : ['(min-width: 700px) handheld and (orientation: landscape)'],
        csspath      : '../public/css/',
        raw          : 'h1 { color: green }',
        stylesheets  : ['lib/bootstrap/dist/css/bootstrap.css', 'src/public/css/main.css'],
        ignoreSheets : [/fonts.googleapis/],
        urls         : ['http://localhost:3000/mypage', '...'] // Deprecated
        timeout      : 1000,
        report       : true,
        htmlroot     : 'public'
    };

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

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

/* Check out how much you've reduced your filesize! */
uncss(files, function (error, output, report) {
    console.log(output);
    console.log('Original: ', report.original/1000, 'kilobytes');
    console.log('Tidy: ', report.tidy/1000, 'kilobytes');
});

/* Specifying raw HTML
 * NOTE: raw HTML is not parsed by PhantomJS
 */
var raw_html = '...'
uncss(raw_html, options, function (error, output) {
    console.log(output);
});

At build-time

UnCSS can also be used in conjunction with other javascript build systems, such as Grunt or Gulp! Thanks to @addyosmani for creating:

and to @ben-eb for creating:

From the command line:

Usage: uncss [options] <file or url, ...>
       e.g. uncss http://getbootstrap.com/examples/jumbotron/ > stylesheet.css

Options:

  -h, --help                           output usage information
  -V, --version                        output the version number
  -i, --ignore <selector, ...>         Do not remove given selectors
  -m, --media <media_query, ...>       Process additional media queries
  -C, --csspath <path>                 Relative path where the CSS files are located
  -s, --stylesheets <file, ...>        Specify additional stylesheets to process
  -S, --ignoreSheets <selector, ...>  Do not include specified stylesheets
  -r, --raw <string>                   Pass in a raw string of CSS
  -t, --timeout <milliseconds>         Wait for JS evaluation
  -H, --htmlroot <folder>              Absolute paths' root location
  • ignore (Array): provide a list of selectors that should not be removed by UnCSS. For example, styles added by user interaction with the page (hover, click), since those are not detectable by UnCSS yet. Both literal names and regex patterns are recognized.

  • media (Array): By default UnCSS processes only stylesheets with media query "all", "screen", and those without one. Specify here which others to include.

  • csspath (String): path where the CSS files are related to the html files. By default, UnCSS uses the path specified in the <link rel="stylesheet" href="path/to/file.css">

  • stylesheets (Array): use these stylesheets instead of those extracted from the html files.

  • ignoreSheets (Array): do not process these stylesheets, e.g. Google fonts. Accepts strings or regex patterns

  • raw (String): give the task a raw string of CSS in addition to the existing stylesheet options; useful in scripting when your CSS hasn't yet been written to disk.

  • urls (Array): array of URLs to load with Phantom (on top of the files already passed if any). NOTE: this feature is deprecated, you can pass URLs directly as arguments.

  • timeout (Number): specify how long to wait for the JS to be loaded.

  • htmlroot (String): Where the project root is. Useful for example if you are running UnCSS on local files that have absolute href to the stylesheets, i.e. href="/css/style.css"

License

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

Keywords

FAQs

Package last updated on 30 Jan 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc