CSS Transparency Using RGBA


Use the RGBA() values for CSS transparency. Set the alpha channel parameter to specify the opacity for color −

.transparent {
   background-color: rgba(0, 0, 255, 0.582);
}

RGBA color value includes the rgba(red, green, blue, alpha). Here, the alpha is to be set for transparency i.e. −

  • 0.0: fully transparent

  • 1.0: fully opaque

Transparency With RGBA

The following is the code for implementing CSS transparency using RGBA. Here, we have set the alpha parameter to a value 0.582 for transparency −

Example

<!DOCTYPE html>
<html>
<head>
   <style>
      body {
         font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
      }
      div {
         width: 200px;
         height: 200px;
         background-color: rgb(0, 0, 255);
         color: white;
         display: inline-block;
      }
      .transparent {
         background-color: rgba(0, 0, 255, 0.582);
      }
   </style>
</head>
<body>
   <h1>Transparency using RGBA example</h1>
   <div class="transparent">
      This is a demo text.
   </div>
   <div>
      This is another demo text.
   </div>
</body>
</html>

Full Transparency With RGBA

The following is the code for implementing CSS transparency using RGBA. Here, we have set the alpha parameter to a value 0.0 for full transparency −

Example

<!DOCTYPE html>
<html>
<head>
   <style>
      body {
         font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
      }
      div {
         width: 200px;
         height: 200px;
         background-color: rgb(0, 0, 255);
         color: white;
         display: inline-block;
      }
      .transparent {
         background-color: rgba(0, 0, 255, 0.0);
      }
   </style>
</head>
<body>
   <h1>Transparency using RGBA example</h1>
   <div class="transparent">
      This is a demo text.
   </div>
   <div>
      This is another demo text.
   </div>
</body>
</html>

Fully Opaque With RGBA

The following is the code for implementing CSS transparency using RGBA. Here, we have set the alpha parameter to a value 1.0 for fully opaque −

Example

<!DOCTYPE html>
<html>
<head>
   <style>
      body {
         font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
      }
      div {
         width: 200px;
         height: 200px;
         background-color: rgb(0, 0, 255);
         color: white;
         display: inline-block;
      }
      .transparent {
         background-color: rgba(0, 0, 255, 1.0);
      }
   </style>
</head>
<body>
   <h1>Transparency using RGBA example</h1>
   <div class="transparent">
      This is a demo text.
   </div>
   <div>
      This is another demo text.
   </div>
</body>
</html>

Updated on: 31-Oct-2023

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements