My favorite CSS hack

Gajus Kuizinas
2 min readSep 4, 2019

There is one CSS snippet that I have been copy-pasting for 5 years:

* { background-color: rgba(255,0,0,.2); }
* * { background-color: rgba(0,255,0,.2); }
* * * { background-color: rgba(0,0,255,.2); }
* * * * { background-color: rgba(255,0,255,.2); }
* * * * * { background-color: rgba(0,255,255,.2); }
* * * * * * { background-color: rgba(255,255,0,.2); }
* * * * * * * { background-color: rgba(255,0,0,.2); }
* * * * * * * * { background-color: rgba(0,255,0,.2); }
* * * * * * * * * { background-color: rgba(0,0,255,.2); }

^ This is one of my favourite inventions.

I first shared it on Quora in 2014 (What are the most interesting HTML/JS/DOM/CSS hacks that most web developers don’t know about?) and I still get notifications of someone upvoting this answer daily.

But what does this horrible thing do?

It is meant to be used when you are working with layout, e.g.

The problem is that unless the element on the page has a solid background or it is a picture, you do not see how does it fit into the layout, e.g. most of the text nodes, pictures with transparency, etc.

With the above CSS applied you will see something along the lines of:

Different depth of nodes will use different colour allowing you to see the size of each element on the page, their margin and their padding. Now you can easily identify inconsistencies.

Since I have shared this originally on Quora and Dev.to, multiple people contributed various browser extensions to automate insertion of this CSS snippet. My favourite approach is one proposed by Victor Castro. It uses javascript: URL to inject the above CSS snippet and it adds a red outline.

What are your favorite tricks for debugging HTML/ CSS?

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Gajus Kuizinas
Gajus Kuizinas

Written by Gajus Kuizinas

Founder, engineer interested in JavaScript, PostgreSQL and DevOps. Follow me on Twitter for outbursts about startups & engineering. https://twitter.com/kuizinas

Responses (5)

What are your thoughts?

I have been using a extension for a while that it basically does this, and I find it very useful. If anyone is curious this is the name of the extension.
Pesticide for Chrome

What a horrible little creation. Thanks!