Home > Web Design > HTML Colors

HTML Color Demonstration

The promised bittersweet anecdote and a short explanation of the hexadecimal numbering system are at the bottom of this page. (Promised, that is, if you came here from my home page. If you came here from a search engine, you won't know what I'm talking about.)

HTML lets you specify color as a six-digit hexadecimal number in the form "rrggbb", where "rr" is the red strength, "gg" is the green strength and "bb" is the blue strength. The (hexadecimal) numbers range from 00 to FF, with 00 being the weakest. You specify the background color with the HTML key word "bgcolor". "bgcolor" works in the "body", "table", "tr" and "td" statements.

You specify the text color with the HTML key word "text" in the "body" statement or the HTML "color" key word in the "font" statement. Feel free to click on "View -> Source" to see how I did it on this page.

In most of the examples below, the background color is the first number, and the text color is the second number. For example, the first cell in the table below is pure red (FF0000) with cyan (00FFFF) text; it is labeled "FF0000/00FFFF".

Primary Colors

Here are the primary and secondary colors. Note that in HTML (and computers in general) the primary colors are red, green and blue. Yellow, again according to computers, is a secondary color made up of red and green.

FF0000/00FFFF 00FF00/FF00FF 0000FF/FFFF00
00FFFF/FF0000 FF00FF/00FF00 FFFF00/0000FF

Half Strength

Here are the primary and secondary colors at half-strength, with the other color(s) set to 00, which makes them darker. Note that these are not browser-safe. (See below).

800000/FFFFFF 008000/FFFFFF 000080/FFFFFF
008080/FFFFFF 800080/FFFFFF 808000/FFFFFF

Table above reversed - primary and secondary colors at half strength, the other color(s) set to full strength (FF), which makes them lighter. Again, these are not browser-safe.

FF8080/000000 80FF80/000000 8080FF/000000
80FFFF/000000 FF80FF/000000 FFFF80/000000

More Combinations

There are 256 possible strengths for each of the three colors. (0 - 255; 0 counts as a strength.) That means there are 16,777,216 possible color combinations (256 x 256 x 256). This page isn't big enough to show them all.

Besides that, not every browser is set to show that many colors. There are 216 "Browser-Safe" colors. These will look the same on any browser; you are "safe" to use them. They are all the combinations of 00, 33, 66, 99, CC and FF. Six strengths of three colors makes (6 x 6 x 6) or 216 colors. You'll notice this table has just one number, the background color. The text color in the table is either black, white or yellow.

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

Here's four shades of grey, with five different text colors. In each row the first box is the background color in hex.

333333 FFFFFF FF0000 00FF00 0000FF 000000
666666 FFFFFF FF0000 00FF00 0000FF 000000
999999 FFFFFF FF0000 00FF00 0000FF 000000
CCCCCC FFFFFF FF0000 00FF00 0000FF 000000

Hexadecimal (Base 16)

Regular numbers are based on tens. When you write "43" it means "4 tens and 3 ones". The regular number system is called "base 10" or "decimal". Hexadecimal is based on sixteens. When you write "43" in hexadecimal it means "4 sixteens and 3 ones". "43" in hexadecimal is thus (4x16) + 3 = 67 in base 10. A single digit in base 10 can have the value 0 through 9. A single digit in hexadecimal can have the value 0 through 15. We don't have a single digit that means "ten", so hexadecimal uses letters. In hexadecimal, A = 10, B = 11, C = 12, and so on to F, which is 15.

The highest possible two-digit number in base 10 is 99. The highest possible two-digit number in hexadecimal is FF. It means "15 sixteens and 15 ones", which is 255 in base 10.

To convert a two-digit hexadecimal number to base 10, multiply the left digit by 16 and add the right digit. For example, "A5" = (10x16) + 5 = 165. To convert a base 10 number between 00 and 255 to a hexadecimal number, divide by 16. Put the answer in the left digit and the remainder in the right digit. For instance, 180/16 = 11 remainder 4, so 180 in base 10 is "B4" in hexadecimal.

(No jokes about "That was 180 I met you" allowed.)

If you want to adjust a color by just a smidgen and don't want to add or subtract in hexadecimal, convert to base 10, add or subtract, and convert back to hexadecimal. Real men, however, will just add and subtract in hexadecimal. Keep reading for an anecdote about adding and subtracting in hexadecimal.


Anecdote

In 1973 I was teaching 8th grade math for $7,000 a year. One week we were studying how to add and subtract in bases other than 10; base 2, base 8, base 12, base 16, base negative 3. It was tough sledding, partly because I wasn't good at explaining things, partly because they had other things on their mind, partly because my discipline was shoddy. One morning a student raised her hand and told the whole class "My grandfather said I would never use this stuff."

I wasn't a genius at explaining things, and I couldn't get a class to stay quiet to save my life, but I was smart enough to know I shouldn't tell her "You're right - I've been wasting everyone's time with busy work."

The next choice, "You're right, Night Light - the most you can hope for is to marry someone who has a steady job and a dental plan" was equally bad.

The last choice, telling her that Gramps was a fool, wasn't going to win me any points either. I knew scientists and engineers used different bases all the time, but I couldn't think of an ordinary job that used them. (This was 1973, remember, the dawn of the computer age, when mainframes were powered by steam and PC's by a crank on the side.)

So, I rambled on about how you just never know and how the average American changes jobs every five years. The next month I beat the average by four years and ten months, having been fired for inability to maintain classroom discipline.

Six months after that, I was working as a Programmer Trainee on an IBM 370 mainframe in San Francisco for $10,000 a year. When one of my programs crashed, the machine spit out what was called a "core dump", on paper, in hex, and I had to figure out what had gone wrong by adding and subtracting in hex. I got a lot of practice adding and subtracting in hex in the first couple of months.

I often wonder what that little girl did with her life, and if she is using hex today. She probably uses "Front Page" and doesn't know you can write raw HTML.



This is a page in my site's section on Web Design. The section has a page for:
Student Web Site suggestions
Church Web Site suggestions
HTML colors and Hexadecimal numbers
Usability suggestions for any non-profit organization with a volunteer web master.
You might also like the essay, My Adventures as a UU Web Master, a talk I gave to my church about being their web master.



Sections of my web site:

Home | Christmas Letters | Genealogy | Homilies | Misc. Essays | Peace Corps | Web Design

Problems, comments or complaints? Need an opinion? Send E-mail to:
This page updated: June 21, 2014