Skip to main content

HTML RGB and RGBA Colors

An RGB color value mixes red, green, and blue light sources. An RGBA color value extends RGB with an Alpha channel, which sets opacity (how see-through the color is).


RGB Color Values

An RGB color is written as rgb(red, green, blue). Each value sets the intensity of that light from 0 to 255, giving 256 x 256 x 256 = 16,777,216 possible colors.

For example, rgb(255, 0, 0) is red, because red is at its highest (255) and the others are 0. rgb(0, 255, 0) is green for the same reason. Set all three to 0 for black, and all three to 255 for white.

Example

Six colors set with RGB values.

Prompt
A page showing six colored blocks, each background set with an RGB value: rgb(255,0,0), rgb(0,0,255), rgb(60,179,113), rgb(238,130,238), rgb(255,165,0), and rgb(106,90,205). Each block is labeled with its value.
Output: complete HTML page

Shades of Gray

Shades of gray are made by using the same value for all three parameters.

Example

Six shades of gray made with equal RGB values.

Prompt
A page showing six shades of gray as blocks, each background set with equal RGB values: rgb(60,60,60) through rgb(240,240,240).
Output: complete HTML page

RGBA Color Values

RGBA extends RGB with an Alpha channel that sets opacity. It is written as rgba(red, green, blue, alpha), where alpha is a number from 0.0 (fully transparent) to 1.0 (fully opaque).

Example

One color shown at six opacity levels with RGBA.

Prompt
A page showing the same RGB color rgb(255,99,71) at six opacity levels using RGBA, alpha from 0 (fully transparent) to 1 (opaque), each block labeled with its value.
Output: complete HTML page