<body style="background-color:rgb(0,0,0)">
<div style="background-color: rgba(0, 255, 0, 0.5)">
rgba(0, 255, 0, 0.5)
</div>
<div style="background-color: rgb(0, 127, 0)">
rgb(0, 127, 0)
</div>
</body>
Here is a jsbin: https://jsbin.com/sifirebuxa/edit?html,css,output
Screenshot of what I see (Chrome Version 109 Mac OS X):
I expected the two divs to have equal colors. But I can see visually and verify with color-picker tools that they do not match in my browser.
I've read in many places that alpha blending works via the formula:
mix(c1, c2, a) = c1*(1-a) + c2*a
But based on this experiment, this does not seem to be true in modern browsers.
My color-picker (gimp) tells me that the rendered rgb color of the top div is rgb(19, 128, 13)
. I find this quite surprising: why would mixing green with black cause red and blue to increase, and why would they increase by differing amounts?
Can anyone explain the calculation that would result in rgb(19, 128, 13)
?
In Firefox, the colors appear much much closer, perhaps identical.