CSS RGB Colors

RGB values

In CSS, the following formula can be used to specify colors as RGB values:

rgb(green blue

each parameter (green, as well as blue) defines color intensity between 0 and 255.

For example, rgb(255, 0, 0) is displayed as red because red is set to the maximum value (255), and the others are set to 0.

To display black, set all color parameters to 0 as shown below: rgb(0, 0, 0).

To display white, set all color parameters to 255 as shown below: rgb(255, 255, 255).

Please experiment by mixing the following RGB values:

 

RED

255

GREEN

0

BLUE

0

Example

rgb(255, 0, 0)
rgb(0, 0, 255)
rgb(60, 179, 113)
rgb(238, 130, 238)
rgb(255, 165, 0)
rgb(106, 90, 205)

Try It Yourself

通常 for all three light sources, equal values are used to define gray shadows:

Example

rgb(0, 0, 0)
rgb(60, 60, 60)
rgb(120, 120, 120)
rgb(180, 180, 180)
rgb(240, 240, 240)
rgb(255, 255, 255)

Try It Yourself

RGBA values

RGBA color values are an extension of RGB color values with an alpha channel - it specifies the opacity of the color.

RGBA color values are specified as:

rgba(green blue alpha

alpha The parameters are numbers between 0.0 (fully transparent) and 1.0 (fully opaque):

Please experiment by mixing the following RGBA values:

 

RED

255

GREEN

0

BLUE

0

ALPHA

0

Example

rgba(255, 99, 71, 0)
rgba(255, 99, 71, 0.2)
rgba(255, 99, 71, 0.4)
rgba(255, 99, 71, 0.6)
rgba(255, 99, 71, 0.8)
rgba(255, 99, 71, 1)

Try It Yourself