Question

I've a simple question: If I'm not going to use Alpha on RGBA, for some colors, should I use HEX on these colors? Is there something HEX has that RGBA doesn't? Like browser compatibility, for example? Or is it just fine to use RGBA all the time? I find it better, cause if I would want to use Alpha, I could. Thanks in advance.

Was it helpful?

Solution

Both should be compatible with any standards-compliant browser.

Edit: There might be some buggy behavior in IE (suprise!): http://css-tricks.com/ie-background-rgb-bug/

OTHER TIPS

When using RGBA, I believe the correct syntax is to use R, G, B values. Hence the name. I've not tried using Hex instead, that may result in unexpected behavior.

In terms of browser compatibility, Hex and RGB are pretty much same/same.

Form a browser compatibility stand point there is nearly no real difference in any modern-ish Browser.

Where you can, I'd go with HEX. Shorter, one string and therefore easier to copy to third party programs (e.g. Photoshop, etc.) and also you don't have the IE bug mentioned by Erty.

I tend to use RGBA only where I need alpha, on all other elements I use HEX.

You could actually (almost) always use Hex.

Even when you need alpha there's a way to convert the RGBA value to an equivalent Hex value as long as the background color (under the element with rgba) is a single solid color.

The algorithm for this conversion is here.

Source => Target = (BGColor + Source) =
Target.R = ((1 - Source.A) * BGColor.R) + (Source.A * Source.R)
Target.G = ((1 - Source.A) * BGColor.G) + (Source.A * Source.G)
Target.B = ((1 - Source.A) * BGColor.B) + (Source.A * Source.B)

( I've actually used it a few times, and it works well for me.

As mentioned in previous answers, the gain over here is that the intended RBGA color will look like it should in ie8 and down.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top