Understanding How HTML Color Codes Work

Ever wonder how HTML color codes are put together? For the beginner, it can look like lots of numbers and letters that make no sense. In reality, HTML color codes are written that way for a specific reason that we'll look at in this article.

Introduction to the Hexadecimal System

In mathematics, the hexadecimal or simply hex is a numeral system with a base of 16 usually written using the symbols 0-9 and AF. The numbers 0-9 have the same value as in the decimal system but starting with the letter A, the value keeps going up one up to the value of 16. A is worth 10, B is worth 11 and so forth until you get to F which is worth 16.

How the HTML Color Codes are put together

HTML Color codes are composed of six hex numbers that represent a possible 16.7 million color combinations. The hex color codes are built on the RGB color model. R stands for red, G for green, and B for blue. With your typical html code that looks like this: #FFFFFF it breaks down as follows. The first two hex digits #FFFFFF represent 'red'. The second set of two hex digits #FFFFFF represent the color green. The third and final set of two hex digits #FFFFFF represent the color blue.

A brief overview of the RGB model

The RGB color model, like the HTML color model can represent a total of 16.7 million colors. By varying the among of red, green, and blue, one can come up with any of 16.7 million colors. Each RGB value is represented by a number from 0 to 255. So a set of RGB values ​​for the color white for instance, would look like this: 255, 255, 255.

Putting HTML and RGB Together

We've already established the hex numeral system with it's number range between 0 to 16. Now, when you combine two hex numbers, you can represent any number between 0 and 255. As you can see, RGB and HTML color codes represent the same color model.

Websafe Color Palette

Years ago, monitors could only display 256 colors. These monitors were still popular when HTML was first put together. As such, it was necessary to put together a list of colors that web designers could be sure any given monitor could properly display. Web safe colors are the result. The websafe color palette is made up of 216 colors.

It is always good practice to pick standard colors across the board, but it is no longer absolutely necessary to stick with web safe colors. Doing so now is more for purposes of holding to standard than it is for necessity. One exception to this rule may be developing websites for cellphones and PDA's. Having said that, these devices are now surpassing this barrier as well.

#FFFFFF Represents the color white. # 000000 represents the color black with every other color in between. I hope you now have a much better idea of ​​why HTML color codes are look the way they do.

Share this:

Building WikiProgramming has been both a personal and professional dream since I was 16. The best way to learn is to teach - and this project allows me to learn while helping others. Its a win win and a way for me to give back. I appreciate any and all support!

Wikiprogramming was developed as a tool for programmers regardless of level; as a place to build a solid foundation of programming languages by using our many tutorials for beginner or intermediate programmers or to use as a point of reference for more advanced work. The concept is to increase the accessibility of learning programming languages and to consolidate them in one place. Wikiprogramming hopes to one day change the way the world learns to program and to enable any one to make his or her ideas a reality.