CSS3 RGB & RGBA

css3 rgba opacity

A guide to using css3 ‘RGB’ & ‘RGBA’, giving us not only the ability to set RGB color/colour but also apply a level of opacity.

CSS 3 RGB

The HSL declaration sets color/colour using Red (R), Green (G) and Blue (B).

Cross Brower Compatability
RGBA is currently better supported in FireFox, Google Chrome and Safari, also not requiring any prefix.
All articles in the CSS3 will be updated to show future support & development.

CSS3 RGB

The above RGB example uses the following CSS 3

  1. CSS 3 RGB
  2. div.L1 { background:rgb(60, 80, 100); height:20px; }
  3. div.L2 { background:rgb(60, 100, 100); height:20px; }
  4. div.L3 { background:rgb(60, 120, 100); height:20px; }
  5. <br />
  6. div.L4 { background:rgb(25, 50, 100); height:20px; }
  7. div.L5 { background:rgb(25, 50, 150); height:20px; }
  8. div.L6 { background:rgb(25, 50, 200); height:20px; }

An example for those on alternative browsers not seeing the different levels of opacity…

 

CSS 3 RGBA

Alpha allows us the ability to set a level of opacity. An element with opacity/alpha value of 1.0 will be fully opaque (visible) while an element with opacity value 0.0 will be the complete opposite, invisible. Any value inbetween will determine how opaque (or transparent) the color or object is against its background.

The above RGBA example is set in another layer containing a background texture and each layer uses the following CSS 3

  1. CSS 3 RGBA
  2. div.L1 { background:rgba(153, 134, 117, 0.2); height:20px; }
  3. div.L2 { background:rgba(153, 134, 117, 0.4); height:20px; }
  4. div.L3 { background:rgba(153, 134, 117, 0.6); height:20px; }
  5. div.L4 { background:rgba(153, 134, 117, 0.8); height:20px; }
  6. div.L5 { background:rgba(153, 134, 117, 1.0); height:20px; }

An example for those on alternative browsers not seeing the different levels of opacity…

 

The Zen Elements CSS3 Series

Thank you for reading!
@zenelements // Alex

Like this article?

Subscribe to our rss, follow our tweets or please help us spread the work & share this with your friends!

Thank you for all your support; have a cookie!

6 Comments on “CSS3 RGB & RGBA”

  1. Chris K 30.01.2009 at 3:20 pm

    Excellent stuff, thanks for this tip!

  2. UlteriorMotives 23.07.2009 at 8:42 am

    Excellent series of little examples!

    This one also works in Opera 10 Beta 2.

  3. Maicon Sobczak 03.06.2010 at 2:08 pm

    Great explanation. I liked the design of your blog.

  4. Andy Killen 20.09.2010 at 10:22 am

    I found while testing RGBa on different browsers/computers that….PC and MAC give different results.

    On Mac it is not as “see through” as on PC, and also that PC can handle .95 opacity when mac can only handle .9 opacity.

    Test on mac (safari, firefox, chrome), PC (firefox, ie8, chrome)

    also for graceful degradation of CSS it’s really important to offer a color to earlier browsers that don’t support CSS3.

    i.e

    #item {backgound-color:#000;background:rgba(0, 0, 0, 0.8);}

    regards
    andy

    ps. shameless advert for my plugin http://share-and-follow.com/wordpress-plugin/ it’s really useful for web dev’s and std users alike. Deals with all your social networking needs.

  5. Zen Elements 25.09.2010 at 3:00 pm

    @Andy – thank you for pointing this out! I’d not come across the difference in opacity levels before and it’s certainly good to know. I’ll be keeping that on post-it for future! I’ll let you away with your shameless advert too ;)

  6. Elo 10.04.2012 at 3:28 am

    Thank you very much for this tutorial. Good explanation.

 

Leave a Reply

(required; who are you?)

(required; we'll keep it safe!)

(optional; promote your site!)