Toggle Element State with Google Chrome and Mozilla Firefox

By  on  

It's much easier to debug CSS than JavaScript since there are many fewer interactions in CSS, and they are much easier emulate. Still, element state debugging isn't simple...until now. Google Chrome's WebInspector and Mozilla Firefox's Firebug have a really sweet feature I just discovered which allows the developer to apply element states for the sake of debugging.

Chrome's WebInspector

Chrome CSS Element State

The image above displays Chrome's "Toggle Element State" button, allowing developers to toggle CSS states via checkboxes.

Firefox's Firebug

Firefox CSS Element State

The image displays Firebug's likewise menu, triggered by the down arrow on the CSS tab for an element.

This allows active CSS state bugging vs. simple CSS explorations to be much, much easier. Happy CSS debugging!

Recent Features

  • By
    Regular Expressions for the Rest of Us

    Sooner or later you'll run across a regular expression. With their cryptic syntax, confusing documentation and massive learning curve, most developers settle for copying and pasting them from StackOverflow and hoping they work. But what if you could decode regular expressions and harness their power? In...

  • By
    From Webcam to Animated GIF: the Secret Behind chat.meatspac.es!

    My team mate Edna Piranha is not only an awesome hacker; she's also a fantastic philosopher! Communication and online interactions is a subject that has kept her mind busy for a long time, and it has also resulted in a bunch of interesting experimental projects...

Incredible Demos

  • By
    MooTools ContextMenu Plugin

    ContextMenu is a highly customizable, compact context menu script written with CSS, XHTML, and the MooTools JavaScript framework. ContextMenu allows you to offer stylish, functional context menus on your website. The XHTML Menu Use a list of menu items with one link per item. The...

  • By
    Fullscreen API

    As we move toward more true web applications, our JavaScript APIs are doing their best to keep up.  One very simple but useful new JavaScript API is the Fullscreen API.  The Fullscreen API provides a programmatic way to request fullscreen display from the user, and exit...

Discussion

  1. Bruno Seixas

    Great tip, thanks =)

  2. FireBug does this for years. Just click the little arrow next to the style tab. It’s only :hover and :active, though.

  3. Hott Dogg

    The only thing Chrome cant do with states is when I need to debug an element that matches selector parentElement:hover element, for example
    Chrome applies states only to selected element in inspector and when you selected another element, selected state is applied to new element

  4. Next challenge: Debug pseudo elements with web inspector :p

    • the Chrome web inspector already supports pseudo elements.

      Under the Matched CSS rules is a Psuedo element
      I believe the latest version of firebug does similar, but I’m not sure as I haven’t used it in ages

    • Unfortunately you can not select the pseudo element like any other DOM-Element. Technically this is perfectly valid since pseudo-elements are not part of the DOM but I often miss that feature. Pseudo-elements are harder to debug than necessary.

  5. Good stuff, from what I know this has been around for a while already.

    @JAN BECK – not that hard really, you just have to select the main element and scroll down in the inspector panel to see the psuedo elements

  6. Daniel

    it’s also possible to do this with Firefox’ built in developer tools :-)

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