Question

I was trying to code up some color manipulation code and was stuck for a long time with alpha, then I (2 hours later) realized browsers render rgba differently.

I created this test: http://jsbin.com/adekez/2/ add /edit to look at the code

Here are the results in 4 browsers in OSX Lion: http://imgur.com/g2iqu

That is an element with a background of rgba(0,0,0,0.5) on top of white.

My hex calculator says: FF÷2 = 7F.8 which means

Safari at #808080 is correct Firefox at #7F7F7F is off by 1 Opera at #7E7E7E is off by 2 Chrome at #929292 is way off

What's going here, is this a bug in Chrome or do I just not know about colors (true)?

Was it helpful?

Solution

First off

Well, actually Safari and Firefox are both correct: 0xFF = 255, 255 / 2 = 127.5. So 128 may be correct (0x80), but also 127 (0x7F) - depending on the rounding convention of the browser.

Explantion of the issue

These are rounding issues. I don't quite get why there are rounding issues, since 0.5 is representable in binary numbers without precision loss, but there are, in fact rounding issues:

Opera: Opera Screenshot

Chrome: Chrome Screenshot

OTHER TIPS

When I checked in chrome & safari, But I got exact same rgba color #808080 in both. Let us know which browser version you are using.

rgba alpha value issue

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