Latest web development tutorials

HTML Colors


TVs and computer screens display colors by combining Red, Green, and Blue light.

Web colors are colors used in displaying web pages, and the methods for describing and specifying those colors. Colors may be specified as an RGB triplet or in hexadecimal format (a hex triplet) or according to their common English names in some cases. A color tool or other graphics software is often used to generate color values.

In some uses, hexadecimal color codes are specified with notation using a leading number sign (#). A color is specified according to the intensity of its red, green and blue components, each represented by eight bits. Thus, there are 24 bits used to specify a web color, and 16,777,216 colors that may be so specified.


Color Names

With CSS, colors can be set by using color names:

Example

Color Name
  Red
  Orange
  Yellow
  Cyan
  Blue
Try it Yourself »

CSS supports 140 standard color names.


RGB (Red, Green, Blue)

With HTML, RGB color values can be specified 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. Experiment by mixing the RGB values below:

Red Green Blue
255 0 0
     
 
 
 

Example

Color RGB
  rgb(255,0,0)
  rgb(255,255,0)
  rgb(0,255,0)
  rgb(0,255,255)
  rgb(0,0,255)
Try it Yourself »

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

Example

Color RGB
  rgb(0,0,0)
  rgb(128,128,128)
  rgb(255,255,255)
Try it Yourself »

Hexadecimal Colors

With HTML, RGB values can also be specified using hexadecimal color values in the form: #RRGGBB, where RR (red), GG (green) and BB (blue) are hexadecimal values between 00 and FF (same as decimal 0-255).

For example, #FF0000 is displayed as red, because red is set to its highest value (FF) and the others are set to the lowest value (00).

Example

Color HEX
  #FF0000
  #FFFF00
  #00FF00
  #00FFFF
  #0000FF
Try it Yourself »

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

Example

Color HEX
  #000000
  #808080
  #FFFFFF
Try it Yourself »