LESSON 3.06
RGBA Colors
Add transparency to your color palette
Take your color skills further with RGBA values, which let you control not just the color of an element but how transparent or opaque it appears.
๐ก The Concept
CSS RGBA colors build on regular RGB with one extra value โ an alpha channel that controls how transparent the color is. You have learned two ways to specify color in CSS: named colors for quick experiments, and hex codes for precise control. Now it is time to look at the third method โ RGBA โ which adds something neither of the others can: transparency.
What Is RGBA?
RGBA stands for Red, Green, Blue, Alpha. Like hex, it defines color by mixing red, green, and blue channels. The difference is it uses decimal numbers from 0 to 255 for each color channel, and adds a fourth value โ the alpha channel โ that controls transparency on a scale from 0 (fully transparent) to 1 (fully opaque). In the example below I used .5 for the transparency, which is 50%.
/* RGBA syntax: rgba(red, green, blue, alpha) */
h1 {
color: rgba(0, 0, 0, .5);
}
Why Transparency Matters
The alpha channel opens up design possibilities that hex codes simply cannot match. Common use cases include:
- Overlay effects: Place a semi-transparent black or white layer over a background image to make text more readable.
- Subtle highlights: Add a light transparent color behind text without completely obscuring the page background.
- Hover states: Fade a background color in or out on hover for a polished, interactive feel.
RGB vs. RGBA
If you do not need transparency, you can use rgb() without the alpha value. All three lines below produce the same solid blue:
color: rgb(42, 122, 226);
color: rgba(42, 122, 226, 1);
color: #2A7AE2;
Use rgba() when you need that fourth transparency value. Otherwise, hex is typically the shorter and more common choice for solid colors.
๐ฌ Video Demonstration
This video walks you through adding see-through text and backgrounds using RGBA:

Exercise: Try It Yourself
๐ Tools of the Trade: Need a color code? The Hex Color Picker on the Tools of the Trade page makes it easy to find any color. Bookmark it if you have not already.
Open JSFiddle.net.
Step 1. In the HTML panel, add:
<h1>Buffalo in Spring</h1>
Step 2. Paste this into the CSS panel:
body{
background-image:url(http://whitebuffalosolutions.com/WB-Template/images/photo1.jpg);
}
Step 3. Change the h1 color to RGBA with an opacity of .5 and make the font larger:
h1{
color: rgba(255,255,255,.5);
font-size:4em;
}
Check your result against this screenshot of JSFiddle:

The text becomes a faint, see-through white โ the kind of subtle effect you will see on many modern websites.
โ Frequently Asked Questions
Both can make things transparent, but they work differently. The opacity property affects an entire element and everything inside it โ if you set opacity: 0.5 on a div, the text inside also becomes semi-transparent. rgba() applies transparency only to the specific color value, so you can have a semi-transparent background while keeping the text fully opaque. This makes rgba() much more flexible for most design work.
You can use rgba() anywhere a color value is accepted in CSS โ background-color, color, border-color, box-shadow, and more. Transparent text and transparent borders are both common uses, not just backgrounds.
Use hex for solid colors โ it is shorter, more readable, and universally supported in design tools and color pickers. Use rgba() specifically when you need transparency. If the alpha value would just be 1 (fully opaque), hex is the better choice.
Yes. rgba() has been supported in all major browsers for well over a decade, including Chrome, Firefox, Safari, and Edge. You do not need to worry about browser compatibility for this property on any modern project.
An alpha of 1 means the color is completely solid, the same as a hex code. An alpha of 0 means the color is completely invisible โ you see whatever is behind the element instead. Values in between create varying degrees of transparency. An alpha of 0.9 is almost fully opaque, while 0.1 is nearly invisible.
โ Key Takeaways
RGBA colors let you use transparency anywhere you can use color in CSS. This lesson showed you how to write an RGBA value and use the alpha channel to control how see-through a color is. Next, you will explore Google Fonts and text properties, which give you control over how text looks on the page. Typography makes a big difference in how professional a site feels.
Google Ads
The costs of this website are partially offset by revenue from Google Ads.Tools of the Trade
HTML/CSS Lessons
-
-
-
1.3. HTML Tag Preview
-
-
-
2.2. The HTML Framework
-
-
2.4. HTML Headings
-
-
-
-
-
-
3.01. Introduction to CSS
-
3.02. How CSS Cascades
-
-
-
-
3.05. CSS Colors
-
3.06. RGBA Colors
-
-
3.08. Font and Text Properties
-
3.09. Classes and IDs
-
-
-
-
-
4.3. HTML Embedded Images
-
-
-
-
-
-
5.1. CSS Borders
-
5.2. CSS Border Radius
-
5.3. CSS Gradients
-
5.4. CSS Box Shadows
-
5.5. CSS Text Shadows
-
7.1. The Display Property
-
-
-
7.4. The Box Model
-
-
-
-
-
-
9.1. Website Tables
-
9.2. HTML Forms
-
-
9.4. Special Form Fields
-
9.5. Embedding Multimedia
-
-
9.7. Keyboard Shortcuts
-
10.1. What Is a Framework?
-
10.2. Font Awesome Icons
-
-
10.4. Bootstrap Grid System
-
-
10.6. Bootstrap Navigation
-
-
11.2. Purchasing a Domain Name
-
11.3. Website Hosting
-
11.4. Nameservers and DNS
-
11.5. FTP
-
11.6. GitHub Pages
