Skip to main content

CSS Layout Debugger

✓ Published0🌍 Public
Aalessioalex
Last edited Sep 28, 2014
Created on Sep 28, 2014

This tool visualizes CSS layouts by outlining every DOM element on a page with a random valid hex color, making element boundaries and nesting immediately visible. The code queries the document with `document.querySelectorAll("*")` or the `$$` shortcut, then iterates over the NodeList to set each element’s `outline` style property. It generates colors using `Math.random()` and bitwise operations, converting the result to a base-16 string. A second version assigns a hue based on the tag name’s length, grouping similar elements visually.

AI-generated description

CSS Layout Debbuger

A tweet-sized debugger for visualizing your CSS layouts. Outlines every DOM element on your page a random (valid) CSS hex color.

One-line version to paste in your DevTools

Use $$ if your browser aliases it:

~ 108 byte version

[].forEach.call($$("*"),function(a){a.style.outline="1px solid #"+(~~(Math.random()*(1<<24))).toString(16)})

Using document.querySelectorAll:

~ 131 byte version

[].forEach.call(document.querySelectorAll("*"),function(a){a.style.outline="1px solid #"+(~~(Math.random()*(1<<24))).toString(16)})

If you're looking for a proper version that uses a set color per tag type, check out pesticide.io.

Screenshots

Tested from Chrome DevTools:

Tested from Firefox DevTools:

Tested from WebKit Nightlies (Safari):

Tested in IE:

Thanks to gregwhitworth for verifying.

Tag Specific Layout Debugging In 82 Bytes

My original implementation outlined each DOM element on the page with a random (valid) hex color.

Thanks to the work by @aemkei, @p01, @sindresorhus and other commenters, we now have an even shorter version (108 bytes golfed down to 82) that uses a specific hex color per tag name. This lets you visually group elements similar to how pesticide.io does.

for(i=0;A=$$("*")[i++];)A.style.outline="solid hsl("+(A+A).length*9+",99%,50%)1px"

Preview:

Thanks for the awesome help improving this folks <3