CogSci
3
Introduction to Computing

Home

Syllabus

Schedule

Contact Us
Regrade Form

Printable
Version

Department of
Cognitive
Science

RGB Background Color Workbench

(Uses JavaScript and requires Netscape 3.0 or Internet Explorer 4.0 or higher)
Input
Format
Red Green Blue
Decimal (0-255)
Hexadecimal (00-ff)
Binary (00000000-11111111)

RGB Values

The background color of an HTML page is set by using the BODY tag along with the BGCOLOR attribute. The color itself is expressed as a hexadecimal value representing the intensity of red, green, and blue (RGB) light. Red, green, and blue are the primary colors of light; mixing them will produce any desired color.

Binary numbers are what computers use internally to represent numbers. The binary number system is based on 2 (or powers of 2) rather than the normal decimal numbers that we normally use which are based on 10. Each digit in a binary number is either a 0 or 1, and is stored as a single "bit" in the computer.

Occasionally when programming a computer, it is convenient to specify the value that each bit in a number will have. However, binary numbers tend to be very long (many digits). For instance, 10000001 is the same as 129 in decimal! Enter hexadecimal.

Hexadecimal is a number system based on 16, and is a more compact way to express a binary number. Each hexadecimal digit represents 4 bits, or a binary number between 0 and 15 (decimal). The first 10 digits are written 0-9 just as in normal decimal. The rest of the digits (which represent values from 10-15) are written with the letters A-F, with A equal 10 decimal and F equal 15.

If you would like to learn a little more about binary and hexadecimal, visit cg3.binary.html on the same server and directory as this document.

In the RGB value that BGCOLOR uses, there are 2 hexadecimal digits representing each of red, green, blue. That is, there are 8 bits, or one byte per color value. For example:

	<BODY BGCOLOR="#rrggbb">
The "rr" represents one byte, as do the "gg" and "bb". Each byte (2 hex digits) is a hexadecimal number between 0 and FF (which is 255 decimal). The higher the color value, the brighter that component of the color will be.

What To Do

Try different RGB values and see what sorts of colors you get. Simply select a number input format by clicking one of the radio buttons, type in your RGB values using the correct numeric format. Then click the "change" button to see your color.

The values you select will be displayed in the other numeric formats, so you can see the differences in the number systems. You will, of course, have to use hexadecimal values in your <BODY> tag.

Note: your eyes will probably not be able to detect small changes in values. That is, changing the red value from 128 to 127 (decimal) will probably not be very apparent. So use large differences when you are first tinkering. When you are close to a color you like, then you can use smaller changes in value to home in on your color.

Perhaps as a way to get started, try using the hexadecimal format and values of f0 and see if you can create a "yellow".


Terms to Know

BGCOLOR bit byte RGB
Binary BODY hexadecimal

©opyright 1997-2004 Mark R. Wallen
Last updated: Sun Sep 19 12:20:36 2004