CSS Background Transparency

RGBa is a way to declare a color in CSS that includes alpha transparency support. Replace "object-with-transparent-background" with the object you want to have transparent background.

.object-with-transparent-background {
background: rgba(200, 54, 54, 0.5);
}

This allows us to fill areas with transparent color. We have long had ‘opacity‘, which is similar, but opacity forces all child elements to also become transparent.

Declaring a failsafe color

Not all browsers support RGBa, so if the design permits, you should declare a “failsafe” color. This color will be solid. Not declaring one means no color will be applied in browsers that don’t support it.

.object-with-transparent-background {
background: rgb(200, 54, 54); /* The Failsafe */
background: rgba(200, 54, 54, 0.5);
}

Browser Support for RGBa

Browser Works? Failsafe
Firefox 3.0.* Works
Safari Works
Google Chrome 1.0, 2.0 Works
Firefox 2.0.0.* Doesn’t Work Solid Color
Opera 9.6.1 Doesn’t Work Solid Color
IE 5.5 Doesn’t Work No Color
IE 6, IE 7, IE 8 Doesn't Work Solid Colour

A better fallback for IE

Since IE supports conditional stylesheets, we can bust out those and a proprietary Microsoft CSS filter to accomplish the same result:
<!--[if IE]>
<style type="text/css">.color-block {
background:transparent; filter:progid:DXImageTransform.Microsoft.gradient(startColorstr=#99000050,endColorstr=#99000050);
zoom: 1;
}</style>
<![endif]-->

0