Detect Unmatched CSS Selectors with Helium

By  on  

One thing I can't stand is extra code.  Whether it's an extra CSS or JavaScript file that's been included by the page, bloated HTML, or unoptimized images, we're making our millions of of desktop and mobile visitors pay for our laziness and mistakes.  A great tool called Helium is available to help developers detect selectors in their stylesheets that are unmatched or malformed.  Let me show you how it works!

Start by including the script in your page and initializing Helium upon load:

<script type="text/javascript" src="js/lib/helium-css/helium.js" onload="helium.init()" async></script>

As soon as the page is loaded, the developer is presented with a textarea with which they may type page URLs to test.  These pages are then loaded and a report is generated, detailing the unused selectors, malformed selectors, and pseudo-selectors which should be tested manually:

Helium CSS Textarea

Helium CSS Result

Helium is an excellent tool for identifying legacy and unnecessary CSS.  The information provided by Helium allows developers to remove unused CSS or better segment site CSS.  This tool is the perfect utility for developers looking to quickly optimize their CSS code.  In fact, I've not seen a tool so easy to implement and use.  Let me know if you agree!

Recent Features

  • By
    Vibration API

    Many of the new APIs provided to us by browser vendors are more targeted toward the mobile user than the desktop user.  One of those simple APIs the Vibration API.  The Vibration API allows developers to direct the device, using JavaScript, to vibrate in...

  • By
    Write Better JavaScript with Promises

    You've probably heard the talk around the water cooler about how promises are the future. All of the cool kids are using them, but you don't see what makes them so special. Can't you just use a callback? What's the big deal? In this article, we'll...

Incredible Demos

  • By
    Duplicate the jQuery Homepage Tooltips Using MooTools

    The jQuery homepage has a pretty suave tooltip-like effect as seen below: Here's how to accomplish this same effect using MooTools. The XHTML The above XHTML was taken directly from the jQuery homepage -- no changes. The CSS The above CSS has been slightly modified to match the CSS rules already...

  • By
    Multiple Backgrounds with CSS

    Anyone that's been in the web development industry for 5+ years knows that there are certain features that we should have had several years ago. One of those features is the HTML5 placeholder; we used JavaScript shims for a decade before placeholder came...

Discussion

  1. Did you know about mincss, written by our own Peterbe? It seem to serve the same purpose, see http://www.peterbe.com/plog/mincss

  2. Does it do the same job as CSS Usage ? (Firebug extension)

    • PH, this tool appears to support checking selectors across multiple pages. CSS Usage is current page only.

  3. PH, this tool appears to support checking selectors across multiple pages. CSS Usage is current page only.

  4. Very interesting tools , i will try it now.

    Thank you

  5. It’s a handy tool apparently but not a lot of people are using it? It is not efficient enough, or.. I haven’t tried it yet.

Wrap your code in <pre class="{language}"></pre> tags, link to a GitHub gist, JSFiddle fiddle, or CodePen pen to embed!