Using Color Names and Hex Numbers

an article added by: Cleo Velasquez at 09182008


In: Root » Internet and online » Web design tips » Using Color Names and Hex Numbers

French Spanish Portuguese Italian German Japanese Chinese Korean Russian Arabic

Using Color Names and Hex Numbers

When a monitor displays colors on the screen, it uses the three primary colors of light: red, green, and blue (RGB). The monitor takes different amounts of each color, combines them, and projects them onto an area of the screen called a pixel, which stands for ‘‘picture element.’’ If a pixel must be white, then the monitor displays 100 percent of the red, green, and blue light in that pixel. If a pixel must be black, then the monitor displays zero percent of the red, green, and blue light in that pixel. HTML manages these RGB color combinations by using hexadecimal notation (or base-16). Hex notation has a number set from 0 to 15, unlike the 0 to 9 numbers in the decimal notation (base-10) we use every day. Because we can use only one digit in each number place, hex notation uses A through F to denote the numbers 10 through 15. For example, when you translate the number 60 into a hex number, the hex equivalent is 3C. Writing down 3C is much easier than writing 111100 in binary notation.

When you pronounce a hex number that looks like a decimal number, such as 43, you don’t say ‘‘forty-three’’ but ‘‘four three.’’ This precise pronunciation avoids confusion; it’s even better if you say ‘‘four three hex.’’ (However, saying this may require you to reassure the person you’re talking to that you’re not casting a spell on him or her.) Let’s look at an example and play with it a little bit. Remember that a byte is 8 bits and a nibble is 4 bits. Well, when you take a number in binary and covert it into hex you do it a nibble at a time. That makes it easy. The number 60 in binary is 00111100 32 + 16 + 8 + 4 = 60. Each byte has 8 positions from the rightmost ones position to the leftmost 128th position. The ‘‘0’’ entries have no value associated with them. Therefore, you do include the equivalent positional value in the summing. It is just like taking the decimal number 109 and adding it up as one in the hundredths position, plus 0 in the 10s position, plus 9 in 1s position, and having it sum up to 109.

As you can see, these position values are based on the value of 2 raised to a power: 20 being 1, 21 being 2, 22 being 4, 23 being 8, 24 being 16, 25 being 32, 26 being 64, and 27 being 128. If you add them all together (1 + 2 + 4 + 8 + 16 + 32 + 64 + 128), you get 255, which in binary is 11111111. To convert to hex, you take the four rightmost digits and add their corresponding values: 1, 2, 4, and 8, which will equal 15. According to the earlier description of hex notation, you know that 15 in hex is F. You then take the remaining four leftmost digits and add up their positional values: 16 + 32 + 64 + 128, which adds up to 240. Add 240 to 15, and you get 255. Thus, 255 in hex is FF.

Now, the more astute among you will have wondered why 1111 is 15 for the first set of digits on the right, but 1111 is added up to 240 on the left. And, if it is actually 240, how can it be F? Good question, and this is one of the reasons so many of us gave up on math. It makes perfect sense, but it’s difficult to explain. You can really look it at two ways: as two nibbles of 15 each or as 1 byte of 255. We actually look at it as both. We think of the rightmost 4 digits holding their position values of 1, 2, 4, and 8 to have a total value of 15 (F). We think of this right nibble as the remainder of a number. Then we look at the left nibble and we think of its leftmost four digits as holding the positional values of 16, 32, 64, and 128 for a total value of 240. Now, if you divide 240 by 16, you get 15 (1111), which also equals F. Thus, you derive the left nibble as also being F. Thus you get 240 + 15 for 255 (FF). And getting FF when a byte is all ones is a perfect 255.

Remember that a bit is defined as a quantity of information that can be defined as either a yes-no or true-false value. (In other words, a bit is set if its value is 1 to indicate yes or true, and reset if its value is 0 to indicate no or false.) A nibble is 4 bits, and a byte consists of 8 bits. For the second nibble (left F), square the value 15. You’ll get 225. Add 15 to that. You’ll get 240. Then, add the right nibble value (15): 240 + 15 = 255.

Decoding RGB triplets

HTML specifies colors by using a six-digit hex number, called a color code. The color code begins with a pound sign (#) and then the hex number follows. The six-digit hex number actually is a combination of three two-digit hex numbers that denote the RGB values. These RGB ‘‘triplets’’ enable you to set the red, green, and blue values of a color, and the color code combines these values and produces the color. For example, the color code #FF00FF denotes the strongest red (FF), no green (00), and the strongest blue (FF). This color code produces a magenta color on your screen. Here are some additional simple color code examples:

- #FFFFFF White (red, blue, and green)

- #000000 Black (no red, no blue, no green)

- #FF0000 Red

- #00FF00 Green (although the official HTML color name is ‘‘Lime’’)

- #0000FF Blue

If you want a less intense color, you can lower the red, green, or blue color value in the color code. For example, if you want to display a lighter blue, you can use the color code #0000AA.

Facing limitations of named colors

Learning what color code value combinations produce the desired color can be a process of trial and error. Once you do find the color, the number of sticky notes to remind you of the correct color code can cover the entire perimeter of your screen. Fortunately, HTML does have common colors named, so you can enter the name of the color instead of the color code. Table 6-2 summarizes the named colors in HTML and their corresponding color codes.

Using color pickers

There are 216 Web-safe colors, which are colors that display solid colors on any computer, monitor, and Web browser. Colors other than these 216 exhibit dithering geometric patterns appearing in the color that try to give the appearance of more colors. What happens instead is that the dithered colors give the appearance of a freakish-looking quilt or tartan. What’s more, a dithered color will look different on a different browser or on a different computer than the one you are using. So, using Web-safe colors is the only way to ensure that your Web site has a uniform look, no matter who accesses it. One of the other alternatives to the sticky-note path (and an effective way to ensure that your site has Web-safe colors) is to choose your colors from a color picker. If you use a Web authoring program such as Dreamweaver, you can select from Web-safe colors directly in the program. If you choose to program directly in HTML, there are several sources on the Web for you to explore.

The Microsoft Developer Network Web site has a safety palette page at http://msdn2 .microsoft.com/en-us/library/bb250466.aspx. This page, contains all the Web-safe colors displayed in two ways: from beginning to end, and grouped by related colors. When you move your mouse pointer over the color you’re looking for, the color code appears in a box next to the color.

legal disclaimer

Our website is not responsible for the information contained by this article. Web-articles is a free articles resource.
Suggestion: If you need fresh, daily updated content for your website, feel free to use our service. Click here for more information.

related articles

1. Working with Graphics, Sounds, and Videos when creating a website
This article presents the techniques for adding graphics, sounds, and video elements to your Web pages. You find out how to add images and image maps to your Web pages, link and embed sound and video files, and use a background sound that plays when your Web page displays. File Formats for Image, Sound, and Video You can choose from many different file formats for images, sounds, and videos. Fortunately, you can construct most Web pages using only the formats that we describe in the following se...

2. How to publish your website on the web
This article presents the procedures that you must follow to make your Web pages available so that others can see them. You find out how to test your Web pages, publish your Web pages with the Web Publishing Wizard, and use FTP to post Web files. Finally, you discover how to announce your site via the major search services. Previewing Your Web Pages Before you post your Web pages to a Web server, it’s a good idea to test them. You can preview your Web pages from your hard drive with a Web ...

3. How to promote a webiste
Obviously, you want your Web site to be more popular than Britney Spears and it can be, if you promote it well. Search engines, such as Yahoo!, Lycos, Google, and the rest of them, are always scouring the Internet and recording information about Web pages. Individual search engines work a little differently: Some record information about every word on a Web page and some look only at titles and headings. The search engines store this information in giant databases. When you conduct a search of the Intern...

4. Image editing programs like Adobe Photoshop
Image-editing programs Following are some popular image-editing applications: - The trial edition of Adobe Photoshop CS3 This download is rated highly by users and ranked first in image-editing downloads with more than 8 million to date. This download requires site registration before use. There is also a shareware version available for Apple users. - PhotoImpact X3 This is a user-friendly image editor that actually has most of the editing tools that most people would need and use f...

5. Ilustrator Flash Professional Photoshop Extended and Fireworks
Illustrator The Illustrator application allows the user to efficiently create vector graphics, and then seamlessly use the result with other applications included in CS3. The developer can prepare content for Web, mobile, and print media. The interface of the CS3 version has been modified to provide more efficient utilization of the workspace. For example, the Tools palette has been streamlined from two columns to one that docks inconspicuously along the borders of the screen. Simultaneously, more ...

6. Adobe Creative Suite 3 Photoshop and Dreamweaver
Adobe Creative Suite 3 Photoshop and Dreamweaver The purpose of this article is to provide a brief look at some of the tools available for use in Web site design, and point you to where there is more in-depth coverage of each technology highlighted in later articles. For readers working within the constraints of a variety of budgets, this article describes a range of image-editing tools that are available on the Web either as freeware, shareware, or trial versions of c...

7. How to design a web site for the mobile web
Designing for the Mobile Web There are more than 50 companies producing mobile telephones in significant and marketable quantities. By 2009, projections indicate there will be 3 billion mobile phone users worldwide. The market for the delivery of Web content to these mobile device users dwarfs the market for desktops. There is theoretically unlimited potential for expansion of the Web (or Web 2.0) into these devices, and we are now on the cutting edge of Web site design for Mobile Web (or the ‘‘Ubi...

8. Origins of the Internet and How a router routes
Origins of the Internet One of the first ideas to get out of your mind (if it is there) is that the Internet is a monolithic creation that came about at a single point in time and at a single location. The Internet is a conglomerate of overlapping and mutually reinforcing technologies from computer science, data storage and retrieval sciences (the once lowly data processing), and communications that have been developed (and are still being developed) over the past half century. From inception in the Depart...