HTML Colors RGB

What is RGB?

RGB stands for Red, Green, Blue. It's a color model that creates colors by mixing these three primary colors. Each color channel has a value from 0 to 255, where 0 means no color and 255 means maximum intensity.

RGB Color Syntax

RGB colors are specified using the rgb() function with three values:

Syntax
rgb(red, green, blue)

Each value is an integer from 0 to 255.

Basic RGB Colors

Pure Colors

Example
<p style="color: rgb(255, 0, 0);">Red (255, 0, 0)</p>
<p style="color: rgb(0, 255, 0);">Green (0, 255, 0)</p>
<p style="color: rgb(0, 0, 255);">Blue (0, 0, 255)</p>
<p style="color: rgb(0, 0, 0);">Black (0, 0, 0)</p>
<p style="color: rgb(255, 255, 255);">White (255, 255, 255)</p>

Mixed Colors

Example
<p style="color: rgb(255, 255, 0);">Yellow (255, 255, 0)</p>
<p style="color: rgb(255, 0, 255);">Magenta (255, 0, 255)</p>
<p style="color: rgb(0, 255, 255);">Cyan (0, 255, 255)</p>
<p style="color: rgb(128, 128, 128);">Gray (128, 128, 128)</p>

RGBA (RGB with Alpha/Transparency)

RGBA adds an alpha channel for transparency. The alpha value ranges from 0.0 (fully transparent) to 1.0 (fully opaque):

Example
<div style="background-color: yellow; padding: 20px;">
    <p style="background-color: rgba(255, 0, 0, 1.0);">Red - Fully opaque (1.0)</p>
    <p style="background-color: rgba(255, 0, 0, 0.7);">Red - 70% opacity (0.7)</p>
    <p style="background-color: rgba(255, 0, 0, 0.5);">Red - 50% opacity (0.5)</p>
    <p style="background-color: rgba(255, 0, 0, 0.3);">Red - 30% opacity (0.3)</p>
</div>

Common RGB Color Values

Color RGB Value Example
Red rgb(255, 0, 0) Red
Green rgb(0, 255, 0) Green
Blue rgb(0, 0, 255) Blue
Yellow rgb(255, 255, 0) Yellow
Cyan rgb(0, 255, 255) Cyan
Magenta rgb(255, 0, 255) Magenta
White rgb(255, 255, 255) White
Black rgb(0, 0, 0) Black
Gray rgb(128, 128, 128) Gray

Using RGB in CSS

RGB values can be used in any CSS property that accepts colors:

Example
<style>
    .red-text {
        color: rgb(255, 0, 0);
    }
    .blue-bg {
        background-color: rgb(0, 0, 255);
    }
    .green-border {
        border: 2px solid rgb(0, 255, 0);
    }
</style>

<p class="red-text">Red text</p>
<div class="blue-bg" style="color: white; padding: 10px;">Blue background</div>
<p class="green-border" style="padding: 10px;">Green border</p>

RGB Value Ranges

Converting Between Color Formats

RGB values can be converted to other formats:

Best Practices