Color on the Web

Color is an enhancement.

Color Theory

I don’t want to delve too deeply into Color Theory, but hopefully I can cover just enough so that you’re not too lost.

Color on your screen are based on Red, Green, and Blue as primary colors. There are different color systems that we can use to access those values, each with their own pros and cons. Your computer monitor can’t display every color, but they can display so many that the point is effectively moot (over 9 million in the RGB color space!).

Forget what you were taught in elementary school about color. Modern screens work slightly differently.

The color model, called the subtractive color model, that we learned was that red, blue, and yellow combine to make other colors. In printers the colors cyan (blue), magenta (red), and yellow can be combined to make nearly every other color.

Subtractive Primary Colors

Color on your screen are based on Red, Green, and Blue values. The color model that screens use is called the additive color model. The colors red, green, and blue add up to make white.

Additive Primary Colors

There are different color systems that we can use to access those values, each with their own pros and cons. Using the RGB values we can make millions of colors on the screen.

Millions of colors possible using the RGB color model

Color depth is how we describe the number of colors possible.

1-bit color depth
Only black or white, such as in a simple bit map.
4-bit color depth
16 colors, usually shades of gray, such as in classic Macintosh systems.
8-bit color depth
256 colors, as seen in early video game systems, and early web design.
16-bit color depth
65,536 (thousands) colors
24-bit color depth
16,777,216 (millions) colors, usually describes color in three chanels of 256 values for red, green, and blue.
32-bit color depth
16,777,216 (millions) colors, usually describes color in four chanels of 256 values for cyan, magenta, yellow, and key (black). Primarily used in printing.

Named Colors

A list of names for 140 colors that can be used. Using color names is possibly the worst way to choose colors.

Basic 16 HTML Color List
black
silver
gray
white
maroon
red
purple
fuchsia
navy
blue
teal
aqua
green
lime
olive
yellow
Extended Color List (All 140 Named Colors)
white
ivory
snow
mintcream
azure
floralwhite
honeydew
ghostwhite
seashell
aliceblue
oldlace
lavenderblush
whitesmoke
beige
linen
antiquewhite
mistyrose
mediumvioletred
deeppink
palevioletred
hotpink
lightpink
pink
darkred
red
firebrick
crimson
indianred
lightcoral
salmon
darksalmon
lightsalmon
orangered
tomato
darkorange
coral
orange
darkkhaki
gold
khaki
peachpuff
yellow
palegoldenrod
moccasin
papayawhip
lightgoldenrodyellow
lemonchiffon
lightyellow
maroon
brown
saddlebrown
sienna
chocolate
darkgoldenrod
peru
rosybrown
goldenrod
sandybrown
tan
burlywood
wheat
navajowhite
bisque
blanchedalmond
cornsilk
darkgreen
green
darkolivegreen
forestgreen
seagreen
olive
olivedrab
mediumseagreen
limegreen
lime
springgreen
mediumspringgreen
darkseagreen
mediumaquamarine
yellowgreen
lawngreen
chartreuse
lightgreen
greenyellow
palegreen
teal
darkcyan
lightseagreen
cadetblue
darkturquoise
mediumturquoise
turquoise
aqua
cyan
aquamarine
paleturquoise
lightcyan
navy
darkblue
mediumblue
blue
midnightblue
royalblue
steelblue
dodgerblue
deepskyblue
cornflowerblue
skyblue
lightskyblue
lightsteelblue
lightblue
powderblue
indigo
purple
darkmagenta
darkviolet
darkslateblue
blueviolet
darkorchid
fuchsia
magenta
slateblue
mediumslateblue
mediumorchid
mediumpurple
orchid
violet
plum
thistle
lavender
black
darkslategray
dimgray
slategray
gray
lightslategray
darkgray
silver
lightgray
gainsboro

Color Systems

When you’re in the flow and coding a site quickly, sometimes it’s easiest to just type in a color name and continue developing. The downside is you’re just limited to the named colors. If you wanted a gray that’s between silver and lightgray, you’d be out of luck. But, there are various color systems that you can use to be more specific about the color that you want. The systems that you’ll most likely use on the web are Hexadecimal, RGB, and HSL.

Hexadecimal Colors

A Decimal number is a numbering system that uses the digits 0 through 9. When you get to double digits (the number ten), then we put a 0 in the ones column (10). A Hexadecimal number uses the digits 0 through F. When you get to double digits (the number sixteen), then we put a 0 in the ones column (10). It’s okay to think this is a little strange if this is your first time encountering it.

A Hexadecimal color string start this a hash character (#) and is followed by six Hexadecimal numbers. The first two columns stand for a red value, the second two columns stand for a green value, and the last two columns stand for a blue value. Using a two digit Hexadecimal number from 00 through FF and give you 256 different values (from 0 to 255).

The Web Safe Palette

The web safe palette was developed back when video cards were limited to 8-bit color. The limit on 8-bit video cards was just 256 colors, of which 216 of them made up the web safe palette.

The value for a hex code color looks like this: #00FF00.

Web Safe Palette
Web Safe Color List
#000000
#000033
#000066
#000099
#0000CC
#0000FF
#003300
#003333
#003366
#003399
#0033CC
#0033FF
#006600
#006633
#006666
#006699
#0066CC
#0066FF
#009900
#009933
#009966
#009999
#0099CC
#0099FF
#00CC00
#00CC33
#00CC66
#00CC99
#00CCCC
#00CCFF
#00FF00
#00FF33
#00FF66
#00FF99
#00FFCC
#00FFFF
#330000
#330033
#330066
#330099
#3300CC
#3300FF
#333300
#333333
#333366
#333399
#3333CC
#3333FF
#336600
#336633
#336666
#336699
#3366CC
#3366FF
#339900
#339933
#339966
#339999
#3399CC
#3399FF
#33CC00
#33CC33
#33CC66
#33CC99
#33CCCC
#33CCFF
#33FF00
#33FF33
#33FF66
#33FF99
#33FFCC
#33FFFF
#660000
#660033
#660066
#660099
#6600CC
#6600FF
#663300
#663333
#663366
#663399
#6633CC
#6633FF
#666600
#666633
#666666
#666699
#6666CC
#6666FF
#669900
#669933
#669966
#669999
#6699CC
#6699FF
#66CC00
#66CC33
#66CC66
#66CC99
#66CCCC
#66CCFF
#66FF00
#66FF33
#66FF66
#66FF99
#66FFCC
#66FFFF
#990000
#990033
#990066
#990099
#9900CC
#9900FF
#993300
#993333
#993366
#993399
#9933CC
#9933FF
#996600
#996633
#996666
#996699
#9966CC
#9966FF
#999900
#999933
#999966
#999999
#9999CC
#9999FF
#99CC00
#99CC33
#99CC66
#99CC99
#99CCCC
#99CCFF
#99FF00
#99FF33
#99FF66
#99FF99
#99FFCC
#99FFFF
#CC0000
#CC0033
#CC0066
#CC0099
#CC00CC
#CC00FF
#CC3300
#CC3333
#CC3366
#CC3399
#CC33CC
#CC33FF
#CC6600
#CC6633
#CC6666
#CC6699
#CC66CC
#CC66FF
#CC9900
#CC9933
#CC9966
#CC9999
#CC99CC
#CC99FF
#CCCC00
#CCCC33
#CCCC66
#CCCC99
#CCCCCC
#CCCCFF
#CCFF00
#CCFF33
#CCFF66
#CCFF99
#CCFFCC
#CCFFFF
#FF0000
#FF0033
#FF0066
#FF0099
#FF00CC
#FF00FF
#FF3300
#FF3333
#FF3366
#FF3399
#FF33CC
#FF33FF
#FF6600
#FF6633
#FF6666
#FF6699
#FF66CC
#FF66FF
#FF9900
#FF9933
#FF9966
#FF9999
#FF99CC
#FF99FF
#FFCC00
#FFCC33
#FFCC66
#FFCC99
#FFCCCC
#FFCCFF
#FFFF00
#FFFF33
#FFFF66
#FFFF99
#FFFFCC
#FFFFFF

You create your own colors using any hexadecimal numbers from 0 though F.

#FFFFFF: Pure White
#E4E4E4: Slight Gray
#E4E4FF: Slight Grey favoring Blue
#7F7F7F: Mid-grey by number value
#767676: Mid-grey by contrast *
#FF0000: Pure Red
#00FF00: Pure Green
#00FF00: Pure Blue
#AA0000: A Darker Red
#003300: Darkest Web Safe Green
#66FF66: A Lighter Blue

rgb() color function

The rgb() color function is a CSS function that converts rgb values into a value that the browser will understand. Standard 24-bit color made up of three channels (Red, Green, and Blue), with 256 values (from 0 to 255) for each channel. You’ll most often see this format in image applications like Photoshop or GIMP. The value for an RGB color looks like this: rgb(255, 0, 0).

color: rgb(255, 255, 255);

hsl() color function

The hsl() color function is a CSS function that converts rgb values into a value that the browser will understand. The three values in HSL are Hue, Saturation, and Lightness. What you’ll see on the screen is an RBG color. The value for an HSL color looks like this:

color: hsl(120, 50%, 50%);
Hue
360 degrees of value. Red is at the top at 0 degrees (or 360 degrees), green is at 120 degrees, and blue is at 240 degrees.
Saturation
From 0% saturation (pure gray) to 100% saturation (pure hue).
Lightness
From 0% lightness (pure black) to 50% lightness (pure hue) to 100% lightness (pure white)

Color Properties

The most common color proprties that you’ll use are color, background-color, border-color.

color

color sets the color of the font for the selected element.

background-color

background-color sets the background color of the font for the selected element.

border-color

border-color sets the border color of the font for the selected element.

currentColor value keyword

The currentColor value reflects the value of the color property. If the color of the element changes so will the associated properties using the currentColor keyword.

This is styled text.

This is styled text.

This is styled text.

.currentBox {
  border: 4px solid currentColor;
}
.redBox {
  color: red;
}
.greenBox {
  color: green;
}
.blueBox {
  color: blue;
}
.redBox:hover {
  color: maroon;
}
.greenBox:hover {
  color: lime;
}
.blueBox:hover {
  color: cyan;
}

Exercises

  1. Change the background-color on your web page.
  2. Change the color of the text on your web page.
  3. Change the background-color for all the aside elements of your web page.
  4. Change the background-color for just one section of your web page.