When designing elements for your webpage, you will often be called upon to specify a color. For example, the code for a span shown below specifies that the color of the text within the span will be yellow.
Text
Colors can be specified according to their names, for example "yellow", "green", or "blue". In many cases, these simple color names will work. But what if you want to specify a more sophisticated color like "cornflowerblue"? A particular browser may not recognize a particular color name. It's more reliable to specify colors with an "RGB triplet".
An RGB triplet specifies a color based upon the amounts of red, green, and blue, on a scale from 0 to 255, required to create the color. For example, to create the color cornflowerblue you need red=100, green=149, and blue=237. We could then specify the color of the text within a span using the rgb function as shown below.
Text
This will work fine with style notation, but what if you want to use straight html. Html doesn't recognize the rgb function. In that case, you can specify color using "hexadecimal" notation. Whereas the decimal numbering system uses the characters 0 through 9 to get 10 values, the hexadecimal numbering system uses the characters 0 through f to get 16 values. (After 9 the characters a, b, c, d, e and f are used, as shown below.)
Decimal Hexidecimal Equivilants
dec hex
0 = 0
1 = 1
2 = 2
3 = 3
4 = 4
5 = 5
6 = 6
7 = 7
8 = 8
9 = 9
10 = A
11 = B
12 = C
13 = D
14 = E
15 = F
On first appearance, this looks pretty simple but you need two hexadecimal characters to represent all decimal values from 0 to 255. When you increment decimal 9 by 1, you change the 9 to 0 and put 1 in the ten's place. When you increment hexidecimal F by one, you change the F to 0 and put 1 in the "sixteens" place. Sometimes it's not easy to convert between decimal and hexadecimal in your head.
RGB Triplet for Cornflowerblue
color dec hex
red 100 64
green 149 95
blue 237 ED
We could then specify the color of text within a span using the hexadecimal notation as shown below.
Text
Note that when we indicate the use of hexadecimal notation by placing a pound (#) sign in front of the number, and we don't use commas to separate the color components.
If it's not easy to convert between decimal and hexadecimal in your head, then how do you do it? You can use a calculator that has a decimal to hexadecimal coversion function, or you can learn to think in hexadecimal. For example, what's the next number after CE? That would be CF. what's the next number after CF? That would be D0. Which hexadecimal number is higher 99 or B2? B2 would be higher than 99. It gets easier with experience.
Here's Java Script code for a simple decimal to hexidecimal color converter
function convert(decvalue)
{
var num = parseInt(decvalue);
if(num >= 0 && num < 256)
{
var hexnum = num.toString(16);
alert("#" + hexnum);
}
else {alert("Error!");}
}
It's important to use hexadecimal notation to specify colors when you use DHTML with visual effects, because to create a dynamic color change you have to increment or add a value to a color. The vast amount of color specification on webpages is in hexadecimal notation, so it would be wise to become familiar with it.
Copyright(C) Bucaro TecHelp.
Permission is granted for the below article to forward, reprint, distribute, use for ezine, newsletter, website, offer as free bonus or part of a product for sale as long as no changes are made and the byline, copyright, and the resource box below is included.
About The Author
To learn how to maintain your computer and use it more effectively to design a Web site and make money on the Web visit bucarotechelp.com. To subscribe to Bucaro TecHelp Newsletter visit http://bucarotechelp.com/search/000800.asp
![]() |
|
![]() |
|
![]() |
|
![]() |
Web sites that feature products ? especially furniture or other... Read More
QUESTION: We promote our web site in all our... Read More
If you're not getting a lot of traffic to your... Read More
When your web site sells more than a dozen items,... Read More
The time it takes to load your site can make... Read More
Content is undoubtedly the most important element of a website.... Read More
Contrary to the beliefs of some, advertising for web and... Read More
Building your first website can be very frustrating. It looks... Read More
The HTML editor is usually a webpage design software that... Read More
Almost everything is available on the web? products, services, e-books,... Read More
There are more than billions of Web Sites, running Online... Read More
You know... Before purchasing your product a person comes to... Read More
1. Loading time:try to be below 20kbless number of imagesspecify... Read More
There are many ways to add fancy bells and whistles... Read More
For many webmasters the title of my article may seem... Read More
An attractive and user-friendly Web site is crucial to attracting... Read More
Novice and professional designers alike ? you may probably be... Read More
I've seen articles (and websites) that suggest you can buy... Read More
Internet Explorer, created by microsoft has been the most popular... Read More
There are several graphic software packages available to help you... Read More
1. Don't load your web site with a lot of... Read More
To create your own great banner, you only need five... Read More
You've come up with a great product. You've got the... Read More
Remember the day that you got your new computer (or... Read More
Many times I've seen a web site undergo a revision... Read More
In this article we will be looking at why you... Read More
The top ten fonts for website design might change in... Read More
With an increasing number of employment portals emerging, it is... Read More
Some wise human once said "Learn from the mistakes of... Read More
There are many companies who build websites, all of which... Read More
The concept of web designing based on the nature and... Read More
Want to see an excellently constructed website? As a writer... Read More
What do the key words represent?Key words - these are... Read More
There are two camps when it comes to flash web... Read More
You have only 10 seconds to impress your potential buyer.... Read More
Many websites make the mistake of being all flash and... Read More
If you were like me and you have just started... Read More
Unless you are an inventor, most likely you are selling... Read More
How many times have you clicked on a website only... Read More
Cascading Style Sheets (CSS) allows you to create fast loading... Read More
Let's face it. Buying products and services from the Internet... Read More
Good websites stand out from the masses of boring, hard... Read More
Whether you're hiring a designer who has created 10 sites... Read More
Do your web pages, sales letters or personal presentations include... Read More
There are several very good reasons why you should consider... Read More
What the heck is going on lately? Most internet websites... Read More
Not all links are created equal.While all of your links... Read More
A client asked me, at what point do you change... Read More
Let's look at what your user wants to see at... Read More
Increasing the length of time a visitor is on your... Read More
The most popular method to build webpages today is to... Read More
Unarguably, the most important part of your website is content.... Read More
We have all seen websites showcasing their testimonials either spread... Read More
Do use a consistent look and feel Your site should... Read More
The effective design is this one, which is maximum simplified,... Read More
When you're self-employed, choosing a website designer is a crucial... Read More
Do you want to use unsafe web colors without offending... Read More
Home PageHome page should clearly indicate what the site is... Read More
Geared Up with a website and lots of energy to... Read More
What colors do you have at your website?Can they make... Read More
Content is undoubtedly the most important element of a website.... Read More
Have you put a lot of effort, time, and money... Read More
As a webmaster, you want to keep your visitors content... Read More
Web Design is a very subjective process. Your idea of... Read More
Most people will agree there is nothing more annoying than... Read More
What Will My Site Do?This is the first of eight... Read More
Web Design |