RGB and RGBA Colors

RGB Color Values

An RGB color value represents RED, GREEN, and BLUE light sources.

In HTML, a color can be specified as an RGB value, using this formula:

rgb(red, green, blue)

Each parameter (red, green, and blue) defines the intensity of the color with a value between 0 and 255. This means that there are 256 x 256 x 256 = 16,777,216 possible colors!

For example:

Examples


<p style="background-color:rgb(255, 0, 0);"> MSK </p>
<p style="background-color:rgb(0, 0, 255);"> MSK </p>
<p style="background-color:rgb(60, 179, 113);"> MSK </p>
<p style="background-color:rgb(238, 130, 238);"> MSK </p>
<p style="background-color:rgb(255, 165, 0);"> MSK </p>
<p style="background-color:rgb(106, 90, 205);"> MSK </p>

Shades of Gray

Shades of gray are often defined using equal values for all three parameters:

Examples


<p style="background-color:rgb(60, 60, 60); color:white;"> MSK </p>
<p style="background-color:rgb(100, 100, 100); color:white;"> MSK </p>
<p style="background-color:rgb(140, 140, 140); color:white;"> MSK </p>
<p style="background-color:rgb(180, 180, 180); "> MSK </p>
<p style="background-color:rgb(200, 200, 200); "> MSK </p>
<p style="background-color:rgb(240, 240, 240); "> MSK </p>

RGBA Color Values

RGBA color values are an extension of RGB color values with an Alpha channel, which specifies the opacity for a color.

An RGBA color value is specified with:

rgba(red, green, blue, alpha)

The alpha parameter is a number between 0.0 (fully transparent) and 1.0 (not transparent at all).

Experiment by mixing the RGBA values below:


<p style="background-color:rgba(255, 99, 71, 0);"> MSK </p>
<p style="background-color:rgba(255, 99, 71, 0.2);"> MSK </p>
<p style="background-color:rgba(255, 99, 71, 0.4);"> MSK </p>
<p style="background-color:rgba(255, 99, 71, 0.6);"> MSK </p>
<p style="background-color:rgba(255, 99, 71, 0.8);"> MSK </p>
<p style="background-color:rgba(255, 99, 71, 1);"> MSK </p>




<div class="box" style="background-color: yellow; width: 300px; height: 80px;">
    <h3 style="background-color: rgba(0, 0, 0, 0.3); width: 100px; height: 70px;">Hello</h3>
</div>