Skip to content
Related Articles

Related Articles

How to set color opacity with RGBA in CSS?

View Discussion
Improve Article
Save Article
  • Difficulty Level : Basic
  • Last Updated : 26 Apr, 2021

In this article, we will see how to set the color opacity with RGBA in CSS. RGBA is a color format, basically containing values for red, green, blue respectively and ‘A’ in RGBA stands for Alpha. To set the opacity of color we mainly change the value of alpha. The value of alpha varies from 0.0 (fully transparent) to 1.0 (fully opaque).


class/id { attribute: rgba(val1, val2, val3, val4) }

Example: In the following example, we use the CSS background-color property with alpha value (opacity).


<!DOCTYPE html>
    <h2 style="color:green">
    <b>Setting opacity with rgba</b>
    <p class="para1" style=
        "background-color: rgba(255, 0, 0, 0.0);">
    <p class="para2" style=
        "background-color:rgba(255, 0, 0, 0.9) ;">
    <p class="para3" style=
        "background-color:  rgba(0, 255, 0, 0.3);">
    <p class="para4" style=
        "background-color:  rgba(0, 255, 0, 0.7) ;">
    <p class="para5" style=
        "background-color:rgba(0, 0, 255, 0.4) ;">
    <p class="para6" style=
        "background-color: rgba(0, 0, 255, 1.0);">

Output: We can see that different values of alpha representing the different transparency.


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!