...

View Full Version : Color Hex Codes



PremiumBlend
04-30-2006, 11:27 PM
Can somebody explain to me the difference between using the 3-digit and 6-digit hex codes? I'm used to seeing and using codes such as #FFFFFF. Also, is there a standard? I'm aware that a 3-digit code of #FAC would be a six -digit code of #FFAACC, but what are the advantages of typing 3 less characters.

Arbitrator
04-30-2006, 11:39 PM
The difference is that it's shorter and thus easier to type, easier to remember, decreases the file size (albeit in a minor way), and simply looks cleaner.

All it really does is contract the color code; the numbers stand for #RRGGBB where RGB stand for red, green, and blue respectively, so your #RGB is just a contracted form of the full code.

Note that contracting only works when using CSS. If you try applying a contracted color code like in the deprecated font element and color attribute shown below, it won't work:

Invalid: <font color="#fff">text</font>

You can still reference them as part of JavaScript styles that alter the CSS though:

Valid: <td onmouseover="this.style.background='#000';">content</td>

PremiumBlend
04-30-2006, 11:46 PM
Isn't the point of a DTD and schema to force apps to be stricter to cause less ambiguity? [For example overlapping nested tags and unclosed tags require the browser to be more forgiving of bad code, thus reducing performance and increasing memory used.] It just seems like a step in the opposite direction of WWW standards. I know I'm being nit-picky, but I think a 3-digit color hex code is not necessary. Does anybody else agree?

Arbitrator
05-01-2006, 03:56 AM
Isn't the point of a DTD and schema to force apps to be stricter to cause less ambiguity?Yes, it is. However it's also to make things more efficient. If we were to type everything out all the time we'd be doing things like:

<style type="text/cascadingstylesheet">
</style>

<table>
<tablerow>
<tabledata></tabledata>
</tablerow>
</table>

<unorderedlist>
<listitem></listitem>
<listitem></listitem>
<listitem></listitem>
</unorderedlist>

This, while unambiguous, is a lot more text and thus file size, typing, messy, et cetera; imagine the size difference in a 2000 row table. This is a similar principle to the one used when contracting the CSS properties into shorthand versions. For example, background as opposed to background-attachment, background-color, background-image, background-position, and background-repeat.

oldcrazylegs
05-02-2006, 01:36 AM
short hex #ccc only works in css not html, xhtml or javascript

kewlceo
05-02-2006, 03:05 AM
It's no more ambiguous than something like margin: 0 auto; IMHO.

PremiumBlend
05-02-2006, 05:14 AM
What I meant by ambiguous was that the computer has multiple ways of reading the same thing. I guess its not really ambiguous as it is alternative. When its being processed it needs to read it and check to see which format is being used, then apply that however necessary. As for using <tabledata> instead of <td>, thats just ridiculous. There's no reason to change to the full name, its just a step in the wrong direction. If HTML parsers allowed the tag <tabledata> in addition to <td>, nobody would use the <tabledata> tag.

I realize thats a bit more extreme than the case of 3 extra letters in a 6-digit hex code that CSS parsers deal with. Really, the question my post should have included initially was "Is it really that beneficial for a CSS parser to allow 2 different string representations of the same data when the difference is only 3 characters?"

felgall
05-02-2006, 07:51 AM
The short forms work in Javascript if you are assigning then to style.color or style.backgroundColor. With some web browsers if you set using the short form then that's what you get back if you query it while others translate to the 6 digit form or even the rgb version.

Arbitrator
05-02-2006, 08:51 PM
Really, the question my post should have included initially was "Is it really that beneficial for a CSS parser to allow 2 different string representations of the same data when the difference is only 3 characters?"Heh, what I really think should be dealt with is allowing the use of color names (black, ivory, blue, etc) in place of hex codes or RGB numbers. It just encourages bad practice for those not familiar with coding yet.

VIPStephan
05-02-2006, 08:57 PM
[...] It just encourages bad practice for those not familiar with coding yet.
Those who are not familiar with coding yet don't use CSS anyway 'cause they just open their WYSIWYG editor and mess around until they think it looks ok.

Arbitrator
05-02-2006, 09:00 PM
Those who are not familiar with coding yet don't use CSS anyway 'cause they just open their WYSIWYG editor and mess around until they think it looks ok.Heh, I started coding my first pages by hand using the deprecated <font color="red"> tag before I even knew what CSS was and it still accepts color names over the codes just like CSS.

kewlceo
05-02-2006, 09:17 PM
Heh, what I really think should be dealt with is allowing the use of color names (black, ivory, blue, etc) in place of hex codes or RGB numbers. It just encourages bad practice for those not familiar with coding yet.
In what way do you think it is a "bad practice" exactly?

Arbitrator
05-02-2006, 09:27 PM
In what way do you think it is a "bad practice" exactly?Because they're being lazy and not learning to use hex codes (or RGB). :p

It's not bad practice as in using tables for layout but it's worse than the hex code contraction thing IMO.

kewlceo
05-02-2006, 10:25 PM
Because they're being lazy and not learning to use hex codes (or RGB). :p

It's not bad practice as in using tables for layout but it's worse than the hex code contraction thing IMO.
Although I tend to use the hex codes myself, I see nothing at all wrong with typing the names, provided they're one of the 16 supported by the HTML 4.0 standard. I prefer uniformity in my code (as well as more than 16 colors!), so I use hex codes.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum