Skip to content
Related Articles

Related Articles

Improve Article
How to set color opacity with RGBA in CSS?
  • 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).

Syntax:

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

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

HTML




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

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

RGBA




My Personal Notes arrow_drop_up
Recommended Articles
Page :