HTML RGB and RGBA Colors

  • 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 results in 16,777,216 possible colors.

For example, rgb(255, 0, 0) is displayed as red, while rgb(0, 255, 0) is displayed as green. To display black, set all color parameters to 0 (rgb(0, 0, 0)), and to display white, set them all to 255 (rgb(255, 255, 255)).

RGBA Color Values:

RGBA color values are an extension of RGB with an Alpha channel, specified as:

rgba(red, green, blue, alpha)

The alpha parameter controls the opacity of the color, ranging from 0.0 (fully transparent) to 1.0 (not transparent at all).

HTML HEX Colors

A hexadecimal color is specified with: #RRGGBB, where RR (red), GG (green), and BB (blue) hexadecimal values specify the color components.

In HTML, a color can be specified using a hexadecimal value in the form:

#rrggbb

For example, #ff0000 is red, and #00ff00 is green. #000000 is black, and #ffffff is white.