CSS Background Opacity with Examples


There are many ways in which we can set the background of an element in HTML Opaque using CSS. Let's take a look at a few examples.

Example 1: Opacity Property

    <div class="div-opaque-05">Opacity 0.5</div>
    <div class="div-opaque-08">Opacity 0.8</div>
    
    <style>
    .div-opaque-05 {
      background-color: #000;
      opacity: 0.5; 
      color: #fff;
      padding:10px
    }
    
    .div-opaque-08 {
      background-color: #000;
      opacity: 0.8; 
      color: #fff;
      padding:10px
    }
    <style>
Opacity 0.5
Opacity 0.8

Example 2: Using Hex Color Code Alpha Channel

    .div-opaque-05 {
      background-color: #00000080;
      color: #fff;
      padding:10px
    }
    
    .div-opaque-08 {
      background-color: #00000050;
      color: #fff;
      padding:10px
    }

Example 3: Using RGBA Background Color

Copyright © Code2care 2024 | Privacy Policy | About Us | Contact Us | Sitemap