RGBa Browser Support

Posted on: 2/2/2009   By: Chris Coyier 29 Comments

RGBa is a way to declare a color in CSS that includes alpha transparency support. It looks like this:

div {
   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 and there is no way to fight it (except weird positional hacks) Cross-browser opacity is also a bit sloppy.

With RGBa, we can make a box transparent and leave it’s child elements alone:

Declaring a fallback color

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

div {
   background: rgb(200, 54, 54); /* The Fallback */
   background: rgba(200, 54, 54, 0.5);
}

Do be aware of this bug though, related to not using shorthand in IE 6 and 7.

Browser Support for RGBa

Last updated: 02/07/2010

Browser, Version, PlatformOutcomeFallback
Firefox 3.6 (OS X)Works
Firefox 3.0.5 (OS X, Windows XP, Vista)Works
Firefox 2.0.0.18 (PC)Doesn’t WorkSolid Color
Safari 4 (Developer Preview, v4.0.4, Mac)Works
Safari 3.2.1 (PC)Works
Mobile Safari (iPhone)Works
Opera 10.10 (OS X)Works
Opera 9.6.1Doesn’t WorkSolid Color
IE 5.5 (PC via IETester)Doesn’t WorkNo Color
IE 6 (PC via IETester)Doesn’t WorkSolid Color
IE 7Doesn’t WorkSolid Color
IE 8 (Beta 2 & release version)Doesn’t WorkSolid Color
Google Chrome 1.0.154.43Works
Google Chrome 4.0.249.49Works
Netscape 4.8 (PC)Doesn’t WorkNo Color
SeaMonkey 1.1.14Doesn’t Work Need Info
Sunrise 1.7.5Works
Stainless 0.2.5Works
Flock 2.0.2Works
BlackBerry Storm BrowserWorks
Camino 1.6.6Doesn’t WorkNeed Info

Data gathered from this demo, which includes MORE COMPLETE browser compatibility list.

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]-->

More Information

Responses

  1. Great article Chirs!

    You’ve really covered it well

  2. Brenelz says:

    Nice discussion on rgba… don’t use rgb colors that often, but once this is more cross-browser I am sure it will be used more.

  3. Matias says:

    I wasn’t aware of the IE hack functionality … very nice!

  4. Bjorn says:

    Agree w/ Brenelz, and yes, thanks for laying out that IE hack from Hedger so clearly.

  5. ikthius says:

    I hope the browser start using this, as it seems a reasonable way to do it, easy to program/learn.

  6. Michael says:

    FYI, IE 8 RC1 on Vista doesn’t support it either. :(

  7. Chris says:

    Can we just get rid of IE? I’m sick of spending so much time pampering it.

  8. Soh Tanaka says:

    Nice! Never knew about this.

  9. EVula says:

    IE 5.5 not supporting it? Understandable.

    IE 8? Inexcusable. I’ll just toss this on the incredibly long list of reasons that I get rabid anytime someone says they use IE.

  10. Chris says:

    Camino 1.6.6 falls back to solid colour.
    Camino 2.0b1 Works properly.

  11. Zhuoshi says:

    Very useful!

    Big surprise that IE doesn’t support this, not even IE8.

  12. Patrick says:

    IE not supporting it? sounds like something new! ;-) nice hack, keep up the great work.

  13. IE gives me sucha boner.

  14. Sebastian Steinmann says:

    Opera 10 will support RGBa too ref: http://dev.opera.com/articles/view/presto-2-2-and-opera-10-a-first-look/#opacity

    And cant this be done with a png image too?

  15. Anonymous says:

    With RGBa, we can make a box transparent and leave it’s child elements alone

    You should remove the apostrophe here.

  16. Opera 10 Alpha and later versions fully support RGBA and HSLA.

  17. thatstandardsguy says:

    Just yesterday I read an article about using opacity and was going to write about RGBa being a more modern, even forward-thinking approach.

    Great article Chris, personally I wouldn’t use the IE fix as I believe there’s a performance hit with using CSS expressions (if performance is an issue for the site in question) but agree it completes the article to discuss the method.

    Personally, I would settle for a solid colour being used by IE, but project meetings may dictate otherwise ;-)

  18. I used this already in the last month a web site swe designed. The fallback worked well since it was a dark grungy background anyway. If you are curious http://www.2×3campaign.com the prefooter part.

    Thanks for sharing.

  19. Jonas says:

    Please, fellow designers, stay away from IE hacks! I cannot stand them anymore.

  20. Ben says:

    Really slick… I always used to use a 1 pixel semi transparent png to achieve the same effect. Only dissapointment is the lack of widespread browser support.

  21. kesc says:

    Very nice and informative article, Chris. I was not aware of the IE fallback, that’s a nice trick.

    Anyhow, I’ll stay away from RGBa until browser support (read: IE (besides, in my native country Opera has a bigger marketshare than worldwide)) catches up.

  22. Thank you for sharing… :D
    Biju Subhash

  23. ptamaro says:

    I’m excited to see more of the benefits of CSS3 in action and watch the web get better over time… As always, thanks for all the great tips & tricks.

This comment thread is closed. If you have important information to share, you can always contact me.