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.

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.

CSS 3 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!
Alex | @ZenElements

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!

3 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.

 

Leave a Reply

(required; who are you?)

(required; we'll keep it safe!)

(optional; promote your site!)