Color Codes

There are several different ways to represent color within HTML and CSS. These include:

Color names

We can simply identify colors by name, such as red, blue, or green. Browsers may use different variations for the actual colors, however.

This is NOT recommended for production; however, it’s the easiest way to learn HTML and CSS.

body {background-color: blue;}

RGB values

We specify values for the amount of red, green, and blue. These are quite similar to the hex codes below.

body {background-color: rgb(0,0,255);}

Notes

Each value goes from 0 to 255.

Hex values

This is a common approach to color codes.

We use a hexadecimal code to identify the color. There are six digits to these codes, and they generally occur in pairs

body {background-color: #0000FF;}

Notes

HSL values

We specify the hue, saturation, and lightness values.

body {background-color: hsl(240, 100%, 50%);}

Notes

Alpha Channel

RGBA and HSLA are both modifications of their initial versions (RGB and HSL).

These just add an alpha channel, which is essentially a transparency degree. 0 is transparent while 1 is opaque.

While this seems similar to the opacity property, that property impacts the ENTIRE element rather than just a color.

Web Safe Color Palette

The web color palette is a standard group of 216 colors that will display the same on a Mac or PC. Using the hex system, all numbers will contain collections of 00, 33, 66, 99, CC, and FF.

Today, this is probably outdated and safe to ignore! Further, this is INFORMAL and not standardized.

See https://websafecolors.info/ for more details.

Color choices

Common Color Codes (both hex and rgb)

Other Resources

W3Schools

Color Table

Color Codes

Downloadable color codes