Introducing CSS Prism, a CSS color inspector

At work, all our new sites share a common .css file that provides structure as well as default black/white/gray values. Each site then has a .css file loaded in afterward, which specifies the colors and background images that make redding.com look different than knoxnews.com.

The process of making each new site involves using a previous site’s .css file as a starting point, and modifying its colors values to match the new skin. I’m sure this is a process common to many theming-related workflows. Using TextMate as my editor of choice, I’m not aware of any way to see color values contained in my .css files, and wound up finding (and fixing) a couple stray Redding colors in Knoxnews ‘ .css file after it launched. I decided this shouldn’t happen again.

CSS Prism homepage

So today I’m launching CSS Prism, a CSS color spectrum inspector. Input the path to any .css file, and it’ll output an easy to scan display of all hex colors from the file. Unwanted colors can be edited via a Photoshop-like color picker (using the jQuery color picker) and the resulting .css file can be downloaded for your convenience.

CSS Prism color picker

This project, built of course with Django, has been fun challenge to improve both my jQuery ability and my regular expression comprehension. It also led me to write my first bookmarklet.

CSS Prism spectrum

The CSS Prism Bookmarklet will insert links to any webpage’s linked .css files just inside the body tag.

CSS Prism will be quite helpful to me as I build more sites at work. And if anyone else finds it useful, that’ll make it even more worthwhile.


Discussion
Link to this comment

Awesome work! My first pony is being able to point to an HTML file and you detecting the CSS link from that

July 27th 2009, 10:57 a.m. by James Tauber
Link to this comment

Thanks, James! That's certainly a good idea to implement on the site itself. Right now, that's basically the functionality of the bookmarklet - hit it from any page, and it detects the css links.

I hope to support file uploads in the future, too.

July 27th 2009, 11:13 a.m. by Ryan Berg
Link to this comment

DAMMIT, BERG!! This is freakin sweet. Can't wait to use it on the Texas sites. :)

July 27th 2009, 11:16 a.m. by Will Hortman
Link to this comment

Nice! Looking forward to checking this out.

I have been using FF Web Developer Toolbar:

Information >> View Color Information

Nice work!

July 27th 2009, 12:18 p.m. by Micky
Link to this comment

Cool.

The only problem I faced immediately that it assumes one color value per line. So when you have a compressed stylesheet with everything in just one line, it will only came up with one color value.

July 27th 2009, 12:47 p.m. by slink
Link to this comment

Micky - Well, shit. Looks like I just spent three weeks building something I basically already have installed in my browser. I never thought to look under the "Information" menu.

Looks like the Web Developer functionality is better in that it can get multiple CSS files at once, and won't be tripped up by firewalls. CSS Prism has the advantage of an interface for editing/replacing color values.

Thanks for pointing that out! facepalm

July 27th 2009, 12:53 p.m. by Ryan Berg
Link to this comment

Slink - Yeah, inability to get all the colors from a compressed stylesheet is an unfortunate limitation of the first working draft codebase.

Assuming there's enough interest in continued development, the first item on my todo list is to overhaul the css parsing to not be dependent on having one property per line.

July 27th 2009, 12:56 p.m. by Ryan Berg
Link to this comment

Ryan: I actually prefer the single CSS color method, but probably because I use a single common CSS file to style my overall site structure and then separate CSS files for individual section design. Very handy!

July 27th 2009, 1:14 p.m. by Jesse Gardner
Link to this comment

This would be really cool as a reusable application that will then let users of /admin/ modify a CSS file's colors and then save the file automatically.

July 27th 2009, 7:45 p.m. by Shawn
Link to this comment

Hy Ryan,

You're not alone. I once spent a good chunk of time re-implementing firefox's "web search" contextmenu option.

I run colr.org, and I think CSS Prism is fantastic. The edit / replace / re-download functionality is really well done.

July 28th 2009, 12:57 a.m. by Lloyd Dalton
Link to this comment

Lloyd, sometimes it's fun just trying to make a better wheel. Even when you aren't yet aware of the wheel's existence.

July 28th 2009, 12:30 p.m. by Ryan Berg
Link to this comment

Hi Ryan,

You've created a fantastic tool! Thanks for making it public.

This'll be useful for dealing with picky designers that want to change site colors halfway through a project: "Just send me the updated CSS file!"

July 28th 2009, 2:39 p.m. by Eric
Link to this comment

This looks like a great tool for web designers.

July 28th 2009, 10:04 p.m. by brisbane
Link to this comment

Pretty neat Ryan - you might want to consider sorting the colors by hamming distance.

July 29th 2009, 9:41 p.m. by Chris Dary
Link to this comment

CSS Prism made my life a lot easier

July 29th 2009, 11:17 p.m. by django clark
Link to this comment

Thanks everyone for checking out CSS Prism and passing the link along. I never expected this level of attention and kind words for a project I initially created to solve a specific workflow issue at work. It's good to know there are others finding CSS Prism as useful as I have.

July 30th 2009, 12:48 a.m. by Ryan Berg
Link to this comment

Chris - I take it once the colors were converted to 6 digits and sorted by hamming distance, the output would be a more gradual shift in color from start to finish?

July 30th 2009, 12:52 a.m. by Ryan Berg
Link to this comment

Nice Idea. Please extend to support "real world" stylesheets.

You might want to consider using a "real" css parser instead of regexes. There is a relatively easy to use python library to do that: http://code.google.com/p/cssutils/

July 30th 2009, 8:46 a.m. by Ulrich Petri
Link to this comment

Ulrich - The lack of support for compressed stylesheets (and @imported stylsheets) comes from an early decision based on my original use case for CSS Prism. Obviously, the product has grown since then and CSS parsing needs a major upgrade.

This week I've been experimenting with cssutils as you mentioned, but also more robust regexes. cssutils has certainly been easy to parse with, but I'm curious to see if it would introduce more memory overhead compared to using regexes.

July 30th 2009, 10:27 a.m. by Ryan Berg
Link to this comment

Ryan, guess what's worse than getting told that an app like the one you just launched got built before ...

Beeing in the middle of building one and reading about someone else launching. ;/ I finished mine anyway, since it was my first python project.

Yours looks pretty neat and the color replacement thing is very useful. Although I have built my own I will probably be passing around your link aswell. :)

August 2nd 2009, 5:57 p.m. by SaturnPolly
Link to this comment

SaturnPolly - I just checked out your app - pretty cool stuff! Your default 'grid' view for colors is similar to another view I've been wanting to present on CSS Prism, and the hue-grouped, value-sorted view is freaking awesome.

You're also rockin' on the support for multiple styesheets, links, @import, etc. Aside from a little js quirkiness, it's working really well. Great stuff!

August 3rd 2009, 12:13 a.m. by Ryan Berg

Comments are disabled for this item