rgba() CSS Function
Description
The rgba() CSS function is used to define colors with an explicit level of transparency, combining the red, green, and blue color channels with an alpha channel that controls opacity. The red, green, and blue components accept numeric values from 0 to 255, while the alpha value ranges from 0 (fully transparent) to 1 (fully opaque). This makes rgba() particularly useful when you want to overlay elements or create semi-transparent backgrounds without affecting other content.
Using rgba() allows for greater flexibility than the rgb() function, which does not include transparency. It is commonly applied in background-color or color properties, but it can also be used wherever a color value is accepted, such as borders, shadows, or gradients.
For example, you can create a semi-transparent background for a div like this:
div {
background-color: rgba(255, 0, 0, 0.5); /* Red at 50% opacity */
}
This results in a red overlay that lets underlying content partially show through. Another common use is to apply subtle transparency to text colors:
p {
color: rgba(0, 0, 0, 0.7); /* Dark gray with 70% opacity */
}
The rgba() function is especially powerful when combined with CSS layouts that use layering or overlapping elements, enabling effects that would be difficult to achieve with solid colors alone.
Syntax
rgba() = rgba( <red>, <green>, <blue>, <alpha> )
Values
- <red>This value can be either a <number> or <percentage> where the number 255 corresponds to 100%
- <green>This value can be either a <number> or <percentage> where the number 255 corresponds to 100%
- <blue>This value can be either a <number> or <percentage> where the number 255 corresponds to 100%
- <alpha>Determines how transparent the color is. A value of 1 is fully opaque, while a value of 0 is fully transparent. A value of 0.5 is semi-transparent.
Example
Browser Support
The following information will show you the current browser support for the CSS rgba() function. Hover over a browser icon to see the version that first introduced support for this CSS function.
This function is supported by all modern browsers.
Desktop
Tablets & Mobile
Last updated by CSSPortal on: 31st December 2025
