🔥Limited Offer: Get 50% OFFon AI & Full Stack Courses🔥
Back to HTML Notes
Topic #14

RGB


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

An RGBA color value is an extension of RGB with an Alpha channel (opacity).


RGB Color Values

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 = 16777216 possible colors!

For example, rgb(255, 0, 0) is displayed as red, because red is set to its highest value (255), and the other two (green and blue) are set to 0.

Another example, rgb(0, 255, 0) is displayed as green, because green is set to its highest value (255), and the other two (red and blue) are set to 0.

To display black, set all color parameters to 0, like this: rgb(0, 0, 0).

To display white, set all color parameters to 255, like this: rgb(255, 255, 255).

Example

<div class="w3-row w3-center" style="line-height:80px;color:white;font-size:20px;font-weight:bold;font-family:Consolas, 'Courier New', Courier, monospace">
<div class="w3-col m6 w3-padding">
<div style="background-color:rgb(255, 0, 0);">rgb(255, 0, 0)</div>
</div>
<div class="w3-col m6 w3-padding">
<div style="background-color:rgb(0, 0, 255);">rgb(0, 0, 255)</div>
</div>
<div class="w3-col m6 w3-padding">
<div style="background-color:rgb(60, 179, 113);">rgb(60, 179, 113)</div>
</div>
<div class="w3-col m6 w3-padding">
<div style="background-color:rgb(238, 130, 238);">rgb(238, 130, 238)</div>
</div>
<div class="w3-col m6 w3-padding">
<div style="background-color:rgb(255, 165, 0);">rgb(255, 165, 0)</div>
</div>
<div class="w3-col m6 w3-padding">
<div style="background-color:rgb(106, 90, 205);">rgb(106, 90, 205)</div>
</div>
</div>

Experiment by mixing the RGB values below:

RED

GREEN

BLUE

Shades of Gray

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

Example

<div class="w3-row w3-center" style="line-height:80px;color:white;font-size:20px;font-weight:bold;font-family:Consolas, 'Courier New', Courier, monospace">
<div class="w3-col m6 w3-padding">
<div style="background-color:rgb(60, 60, 60);">rgb(60, 60, 60)</div>
</div>
<div class="w3-col m6 w3-padding">
<div style="background-color:rgb(100, 100, 100);">rgb(100, 100, 100)</div>
</div>
<div class="w3-col m6 w3-padding">
<div style="background-color:rgb(140, 140, 140);">rgb(140, 140, 140)</div>
</div>
<div class="w3-col m6 w3-padding">
<div style="background-color:rgb(180, 180, 180);">rgb(180, 180, 180)</div>
</div>
<div class="w3-col m6 w3-padding">
<div style="background-color:rgb(200, 200, 200);color:#555555">rgb(200, 200, 200)</div>
</div>
<div class="w3-col m6 w3-padding">
<div style="background-color:rgb(240, 240, 240);color:#555555">rgb(240, 240, 240)</div>
</div>
</div>

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):

Example

<div class="w3-row w3-center" style="
    line-height:80px;
    color:white;
    font-size:20px;
    font-weight:bold;
    font-family:Consolas, 'Courier New', Courier, monospace;
    background-image:url(img_bg_eyeicon.png), url(img_bg_transparent.gif);
    background-repeat:no-repeat, repeat;
    background-position:center, top left;
    background-color:#ffffff;">
<div class="w3-col m6 w3-padding">
<div style="background-color:rgba(255, 99, 71, 0);color:#555555;">rgba(255, 99, 71, 0)</div>
</div>
<div class="w3-col m6 w3-padding">
<div style="background-color:rgba(255, 99, 71, 0.2);color:#555555;">rgba(255, 99, 71, 0.2)</div>
</div>
<div class="w3-col m6 w3-padding">
<div style="background-color:rgba(255, 99, 71, 0.4);">rgba(255, 99, 71, 0.4)</div>
</div>
<div class="w3-col m6 w3-padding">
<div style="background-color:rgba(255, 99, 71, 0.6);">rgba(255, 99, 71, 0.6)</div>
</div>
<div class="w3-col m6 w3-padding">
<div style="background-color:rgba(255, 99, 71, 0.8);">rgba(255, 99, 71, 0.8)</div>
</div>
<div class="w3-col m6 w3-padding">
<div style="background-color:rgba(255, 99, 71, 1);">rgba(255, 99, 71, 1)</div>
</div>
</div>

Experiment by mixing the RGBA values below:

RED

GREEN

BLUE

ALPHA

Want to go beyond the notes?

Join CodingNow 2.0's HTML course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available

RGB – FAQs

Quick answers about learning RGB in HTML.

This free note from CodingNow 2.0 explains RGB in HTML — concept, syntax and worked code examples you can copy, run and revise before interviews.
Yes. Every HTML topic on CodingNow 2.0, including RGB, is 100% free with no signup required.
With focused practice, most students grasp RGB in 1–3 days from these notes; pairing it with CodingNow 2.0's mentor-led course takes you to job-ready depth faster.
Use the code examples in this note, then ask doubts for free on the CodingNow 2.0 Community (/community) — expert instructors answer within 24 hours.
WhatsApp
Call NowEnroll Now