Color name in css

Err, umm reaches wildly for an idea - aha!

Because instead of having only a thousand or so named colors, you instead have 16 million colors at your disposal?

Because instead of having only a thousand or so named colors, you instead have 16 million colors at your disposal?

Works for me :slight_smile:

Isn’t it great when we play the guessing game with web specs? =p

Where do you get this “thousand or so named colors” from - the standard only defines black, silver, gray, white, maroon, red, purple, fuchsia, green, lime, olive , yellow, navy, blue, teal and aqua - that’s 16 and not thousands. Any other named colours are proprietary and are not required to be supported by any browser and may equate to different hex values in different browsers where they are supported.

Using rgba() codes you not only have over 16 million different colours available but you can specify any of 256 different levels of transparency for each of those colours giving over 4 billion possible values - which is just a few more than the 16 you can guarantee will work if specified by name.

Just as a best practices issue, it strikes me that designers should stick to one or the other: hexcodes or names. Since you can’t use names for any but a relative few colors, and because there are issues with browsers recognizing names, hexcodes would be the proper way to name colors. Not getting into rgba codes with this answer. :slight_smile:

The thing is that even with hex colours and rgb colours you can get either returned by JavaScript depending on which browser you are running it in - so if you are using JavaScript code that looks up colours then you need to know how both those ways work in defining colours and test for the equivalents. I don’t know of any browser that would try to return the colour name if you queried it from JavaScript though.

Another reason to stop using the named colors, is named colors are a table lookup (slow) while hex or decimal colors are processed (faster).

That whole ‘easier to translate into a machine readable format’ thing.

Though I still don’t get the objection to the X11 colors (the proper name for the ones not in the HTML/CSS spec) on the whole RGB vs. sRGB thing… as if you couldn’t magically say “ok, now they’re sRGB” with a 1:1 translation channel.

Again, there’s legitimate reasons not to use them – Personally I can’t remember anything but the original 4 bit CGA colors – we don’t need to go making things up.

With… 158 named colors by the time the x11 ones are mixed in? (I think that’s how many there are) NOBODY is going to remember those… much less some of the colors bear no resemblance to their name (navajoWhite and Chocolate come to mind).

Besides, is mixing RGB REALLY so hard? R+G=Yellow, G+B=Cyan, B+R=Magenta… hence the original 4 bit CGA color set… the bottom 3 bits working out to.

000 = black
001 == blue
010 == green
011 == cyan
100 == red
101 == magenta
110 == brown/ochre

The fourth bit just making them brighter.

Interesting this topic came up – I’m writing a thumbnail program using PHP’s GD that I’m letting people set the background color for when images are being ‘fit’ or for import of transparencies… So I literally just typed in all 158 named colors as I wanted full support for any way someone wants to type it in. As an array of 3 decimal values, in 3 digit or 6 digit hex, by the CSS names, or by the X11 names.

Though I was thinking of prefixing X11 before each of those so that it eliminates the namespace conflict with W3C colors – given that gray, maroon, purple and green don’t agree between the two. As it is I’ve already got the CGA ones plugged in with their own prefix since those don’t match either – and I actually would like to use those given my whole retrocomputing shtick.

Just curious - how do you specify an rgba() colour code in css? I’ve never come across it. Is it supported by all modern browsers? Or do you mean setting an rgb colour plus an opacity rule?

The following article helps to resolve such queries.
RGBa Browser Support

Thanks, that says it all!