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

RGB / RGBA


RGB Value

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

In CSS, 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 between 0 and 255.

For example, rgb(255, 0, 0) is displayed as red, because red is set to its highest value (255) and the others 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).

Experiment by mixing the RGB values below:

RED

GREEN

BLUE

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>

Shades of gray are often defined using equal values for all the 3 light sources:

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(90, 90, 90);">rgb(90, 90, 90)</div>
</div>
<div class="w3-col m6 w3-padding">
<div style="background-color:rgb(120, 120, 120);">rgb(120, 120, 120)</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(210, 210, 210);color:#555555">rgb(210, 210, 210)</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 Value

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:

RED

GREEN

BLUE

ALPHA

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>

Want to go beyond the notes?

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

Enroll Now — Free Demo Available

RGB / RGBA – FAQs

Quick answers about learning RGB / RGBA in CSS.

This free note from CodingNow 2.0 explains RGB / RGBA in CSS — concept, syntax and worked code examples you can copy, run and revise before interviews.
Yes. Every CSS topic on CodingNow 2.0, including RGB / RGBA, is 100% free with no signup required.
With focused practice, most students grasp RGB / RGBA 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