RGBa Vs Opacity – The Difference Explained

To be able to effectively handle the alpha transparency or opacity of a particular element purely using CSS / HTML was the dream of any web designer. Because, with alpha transparency or opacity they can make visually more beautiful and easily maintained websites with less effort. Now with CSS3 we can achieve these using properties such as RGBa and Opacity.

What is RGBA?
In addition to RGB (Red Blue Green) CSS3 has introduced a new feature to color setting, which is called RGBA. RGBA stands for Red Blue Green Alpha. Here "A" in this property name stands for "Alpha". This additional feature can be used to specify an opacity value for any color. The alpha channel is usually used as an opacity channel. If a pixel has 0% value in its alpha channel, it's completely transparent (and, that, invisible), whereas a value of 100% in the alpha channel gives a fully opaque pixel. We can use this for anything that can take the CSS color property.

Sample CSS Code:
P {background-color: rgba (255, 0, 0, 0.5); }

We can use RGBA now on all new-generation browsers including Firefox 3, Chrome, Safari, and Opera 10, but we will not see the effect in Internet Explorer.

What is Opacity?
The opacity is also a CSS3 property that allows us to directly set the transparency level of a particular element through CSS. The amount of transparency can vary between 0 (fully opaque) and 1 (fully transparent). For eg, in order to achieve 50% transparency for a particular element, we need to set the opacity value as 0.5.

Difference between RGBA and Opacity
Even though both RGBa and Opacity properties are used to control the transparency of an element, they are basically not the same thing. So what are the differences here?

When we apply an opacity value to an element, the opacity value is inherited by all its child elements. Suppose if we apply opacity value to a DIV (div {opacity: 0.5;}), the text, images and all other elements inside that particular DIV will inherit the opacity value and they will become transparent in-turn.

On the other hand RGBa sets the opacity of the color value of that particular element and the transparency is not inherited by its child elements. In other words, RGBA sets the opacity value only for a single declaration.

While we compare the above RGBa and Opacity examples, It is very clear that by setting the opacity property, the element and all its contents including images and texts become transparent. On the other hand the RGBa applies the transparency only to the color value and not to the entity element and it's contents. All the texts and images are fully visible here and only the background color become transparent.

Browser compatibility
So now the question is about browser support. How to handle the lack of support for Internet Explorer or other older version browsers? The answer is to make use of conditional statements to supply solid colors or an alpha transparent PNG image. We can also make use of Rafael Lima's CSS Browser Selector, 1 kb javascript solution that will help us to send browser specific CSS rules.

If you are ready to enhance the user experience of new generation browsers, and also by respecting the older versions, through providing functional and solid fallbacks. Convince your clients now and start exploring the whole new possibilities of features like RGBA and Opacity.

Source by Deepu Balan

Leave a Reply

Your email address will not be published. Required fields are marked *