
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 maintainable websites with less effort. Now with CSS3 we can achieve these using properties such as RGBa and Opacity.
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 fully transparent (and, thus, 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:
1 | 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 won’t see the effect in Internet Explorer.
Live Preview (Screenshot for older browsers)
Sample CSS Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | .round1, .round2, .round3 { -moz-border-radius: 80px; -webkit-border-radius: 80px; width: 154px; height: 154px; position:relative; } .round1 { background-color: rgba(255,0,0,.5); border: 3px solid #ff0000; } .round2 { background-color: rgba(0,255,0,.5); left: 80px; top: -160px; border: 3px solid #00ff00; } .round3 { background-color: rgba(0,0,255,.5); left:40px; top: -250px; text-align: center; color:#FFFFFF; font: bold 26px Arial, Helvetica, sans-serif; border: 3px solid #0000ff; } .round1:hover, .round2:hover, .round3:hover { border: 3px solid #ffff00; } |
Sample HTML Code
1 2 3 | <div class="round1"> </div> <div class="round2"> </div> <div class="round3">HAI</div> |
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.
CSS Code
1 | P { background-color: #7cb01e; opacity: 0.5; } |
Live Preview (Screenshot for older browsers)
Sample CSS Code
1 2 3 4 5 6 7 8 9 10 11 12 13 | .boxA { background-color: rgb(84, 107, 1); opacity: 0.1; } .boxB { background-color: rgb(84, 107, 1); opacity: 0.2; } .boxC { background-color: rgb(84, 107, 1); opacity: 0.3; } .boxD { background-color: rgb(84, 107, 1); opacity: 0.4; } .boxE { background-color: rgb(84, 107, 1); opacity: 0.5; } .boxF { background-color: rgb(84, 107, 1); opacity: 0.6; } .boxG { background-color: rgb(84, 107, 1); opacity: 0.7; } .boxH { background-color: rgb(84, 107, 1); opacity: 0.8; } .boxI { background-color: rgb(84, 107, 1); opacity: 0.9; } .boxA:hover, .boxB:hover, .boxC:hover, .boxD:hover, .boxE:hover, .boxF:hover, .boxG:hover, .boxH:hover, .boxI:hover { opacity: 1.0; color:#FFFFFF; } |
Sample HTML Code
1 2 3 4 5 6 7 8 9 | <div class="boxA">www.deepubalan.com</div> <div class="boxB">www.deepubalan.com</div> <div class="boxC">www.deepubalan.com</div> <div class="boxD">www.deepubalan.com</div> <div class="boxE">www.deepubalan.com</div> <div class="boxF">www.deepubalan.com</div> <div class="boxG">www.deepubalan.com</div> <div class="boxH">www.deepubalan.com</div> <div class="boxI">www.deepubalan.com</div> |
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.
Live Preview (Screenshot for older browsers)
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 entire element and it’s contents. Hence all the texts and images are fully visible here and only the background color become transparent.
So now the question is about browser support. How to handle the lack of support of Internet Explorer or other older version browsers? The answer is to make use of conditional statements to supply solid colours 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.
RGBa vs Opacity: The Difference Explained @ Deepu Balan – Scribblings of a cyber geek…
Difference between two CSS3 properties, RGBa & Opacity explained……
RGBa vs Opacity: The Difference Explained @ Deepu Balan – Scribblings of a cyber geek…
RGBa vs Opacity: Difference between two CSS3 properties explained with examples……
RGBa vs Opacity: The Difference Explained @ Deepu Balan – Scribblings of a cyber geek…
RGBa vs Opacity: Difference between two CSS3 properties explained with examples……
RGBa vs Opacity: The Difference Explained @ Deepu Balan – Scribblings of a cyber geek…
RGBa vs Opacity: Difference between two CSS3 properties explained with examples……
RGBa vs Opacity: The Difference Explained @ Deepu Balan – Scribblings of a cyber geek…
Thank you for submitting this cool story – Trackback from Servefault.com…
[...] This post was mentioned on Twitter by DJ Hennion, musings.it. musings.it said: RGBa vs Opacity: The Difference Explained – http://b2l.me/mg7bb (via @bdeepu) #css #tutorial [...]
[...] This post was mentioned on Twitter by Richie Thimmaiah, thedsign. thedsign said: RT @bdeepu RGBa vs Opacity: The Difference Explained http://bit.ly/ckDvFu #css3 #rgba #opacity #tutorial #webdesign [...]
Social comments and analytics for this post…
This post was mentioned on Twitter by bdeepu: RGBa vs Opacity: The Difference Explained http://goo.gl/fb/gNtc...
[...] RGBa vs Opacity: The Difference Explained [...]
[...] RGBa vs Opacity: The Difference Explained @ Deepu Balan – Scribblings of a cyber geek [...]
[...] RGBa vs Opacity: The Difference Explained [...]
[...] RGBa vs Opacity: The Difference Explained [...]
[...] RGBa vs Opacity: The Difference Explained [...]
[...] RGBa vs Opacity: The Difference Explained @ Deepu Balan – Scribblings of a cyber geek [...]
[...] RGBa vs Opacity: The Difference Explained By Deepu Balan, March 29th, 2010 Site: Deepu Balan [...]
[...] RGBa vs Opacity: The Difference Explained [...]
[...] RGBa vs Opacity: The Difference Explained [...]
[...] RGBa vs Opacity: The Difference Explained [...]
[...] RGBa vs Opacity: The Difference Explained [...]
[...] RGBa vs Opacity: The Difference Explained [...]
[...] RGBa vs Opacity: The Difference Explained [...]
[...] Der Unterschied zwischen RGBa und Opacity. [...]
[...] RGBa vs Opacity: The Difference Explained @ Deepu Balan … [...]
[...] RGBa vs Opacity: The Difference Explained @ Deepu Balan … [...]
[...] 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 maintainable websites with less effort. Now with CSS3 we can achieve these using properties such as RGBa and Opacity. [...]
[...] RGBa vs Opacity: The Difference ExplainedWhen we apply an opacity value to an element, the opacity value is inherited by all its child elements. 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. [...]
[...] RGBa vs Opacity: The Difference ExplainedWhen we apply an opacity value to an element, the opacity value is inherited by all its child elements. 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. [...]
[...] RGBa vs Opacity: The Difference ExplainedWhen we apply an opacity value to an element, the opacity value is inherited by all its child elements. 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. [...]
[...] RGBa vs Opacity: The Difference ExplainedWhen we apply an opacity value to an element, the opacity value is inherited by all its child elements. 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. [...]
[...] RGBa vs Opacity: The Difference Explained When we apply an opacity value to an element, the opacity value is inherited by all its child elements. 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. [...]
[...] 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 maintainable websites with less effort. Now with CSS3 we can achieve these using properties such as RGBa and Opacity. [...]
Monday, 29 March, 2010 at 18:14
Truly awesome, What about IE support I face a big problem with customizing IE to the CSS .
Monday, 29 March, 2010 at 20:52
Excellent, I was wondering about that – thank you for making the difference clear… I like the way you add the screenshots and code examples too.
Thanks Deepu, great post
Tuesday, 30 March, 2010 at 16:21
cool…so cleary
Wednesday, 31 March, 2010 at 22:59
wonderfull. I’m curious, how could rgba be applied to an entire page, instead of just inner divs, such as, applying it to the body tag, in order to create the gradient i see in your stacked divs ?
in my redesign, i currently am using another css technique to achieve a full page gradient without images.
Thanks for reading and great post as well !!
uxepi
Thursday, 1 April, 2010 at 0:00
Great site. A lot of useful information here. I’m sending it to some friends!
Friday, 2 April, 2010 at 15:37
Nice explaned thanks
Monday, 5 April, 2010 at 13:50
wow! I never knew the actual differences between rgb and opacity. The face is I never cared about it. This is so useful!
Thanks for the post!
Wednesday, 7 April, 2010 at 19:48
These really helped me to build my homepage, I can really appreciated if people take some time and write a usefull tutorial.
Wednesday, 28 April, 2010 at 23:34
Great explanation for something often overlooked or misunderstood.
Thanks