JavaScript Tutorial

HTML Colors

HTML colors can be specified using predefined color names, which can come in different forms such as RGB, RGBA, HEX, HSL, and HSLA values. The W3C has defined 16 basic colors which are explained below.

1. Color Names

The simplest way to specify a color is by its name. Here are the 16 named colors and their corresponding color names:

The Sixteen Named Colors Specified with Name
aqua
aqua
black
black
blue
blue
fuchsia
fuchsia
gray
gray
green
green
lime
lime
maroon
maroon
navy
navy
olive
olive
purple
purple
red
red
silver
silver
teal
teal
white
white
yellow
yellow

2. RGB Values

RGB values are defined using the rgb() property. This property takes three values, one for red, one for green, and one for blue. These values range from 0 to 255. To add opacity to a color, the rgba() property can be used, with the last value ranging from 0 to 1. Here are the 16 named colors with their decimal RGB values:

The Sixteen Named Colors Specified with Decimal in the style attribute
aqua
rgb(0,255,255)
black
rgb(0,0,0)
blue
rgb(0,0,255)
fuchsia
rgb(255,0,255)
gray
rgb(128,128,128)
green
rgb(0,128,0)
lime
rgb(0,255,0)
maroon
rgb(128,0,0)
navy
rgb(0,0,128)
olive
rgb(128,128,0)
purple
rgb(128,0,128)
red
rgb(255,0,0)
silver
rgb(192,192,192)
teal
rgb(0,128,128)
white
rgb(255,255,255)
yellow
rgb(255,255,0)

3. HEX Values

Hex values are 6-digit alphanumeric codes preceded by the "#" symbol. The first two digits represent the red value, the next two represent the green value, and the last two represent the blue value. Hex values are preferred over color names because they occupy less space. When CSS files are minified, color names are automatically converted to hex values. Here are the 16 named colors with their hexadecimal values:

The Sixteen Named Colors Specified with Hexadecimal
aqua
#00FFFF
black
#000000
blue
#0000FF
fuchsia
#FF00FF
gray
#808080
green
#008000
lime
#00FF00
maroon
#800000
navy
#000080
olive
#808000
purple
#800080
red
#FF0000
silver
#C0C0C0
teal
#008080
white
#FFFFFF
yellow
#FFFF00

4. HSL Values

HSL stands for Hue, Saturation, and Lightness. Hue is defined from 0 to 360 degrees, while saturation and lightness are represented as percentages from 0 to 100%. Here are the 16 named colors with their HSL values:

The Sixteen Named Colors Specified with HSL (Hue, Saturation, Light) code in the style attribute
aqua
hsl(180,100%,50%)
black
hsl(0,0%,0%)
blue
hsl(240,100%,50%)
fuchsia
hsl(300,100%,50%)
gray
hsl(0,0%,50%)
green
hsl(120,100%,25%)
lime
hsl(120,100%,50%)
maroon
hsl(0,100%,25%)
navy
hsl(240,100%,25%)
olive
hsl(60,100%,25%)
purple
hsl(300,100%,25%)
red
hsl(0,100%,50%)
silver
hsl(0,0%,75%)
teal
hsl(180,100%,25%)
white
hsl(0,0%,100%)
yellow
hsl(60,100%,50%)

5. How to apply these color using the style attribute

We can apply the above-mentioned colors to any of the HTML elements using the style attribute. 

Output:

Supporting Browsers

Element

“Google Chrome

Microsoft

Firefox

Opera

Safari

Color Names

Yes

Yes

Yes

Yes

Yes

RGB Values

Yes

Yes

Yes

Yes

Yes

HEX Values

Yes

Yes

Yes

Yes

Yes

HSL Values

Yes

Yes

Yes

Yes

Yes

Go back to Previous Course