Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 14 of 14

Thread: Color Hex Codes

  1. #1
    Regular Coder PremiumBlend's Avatar
    Join Date
    Apr 2006
    Location
    Marion, Iowa
    Posts
    201
    Thanks
    0
    Thanked 13 Times in 13 Posts

    Color Hex Codes

    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.
    My Website: DumpsterDoggy

  • #2
    Senior Coder Arbitrator's Avatar
    Join Date
    Mar 2006
    Location
    Splendora, Texas, United States of America
    Posts
    3,300
    Thanks
    28
    Thanked 275 Times in 269 Posts
    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>
    Last edited by Arbitrator; 04-30-2006 at 11:42 PM.
    For every complex problem, there is an answer that is clear, simple, and wrong.

  • #3
    Regular Coder PremiumBlend's Avatar
    Join Date
    Apr 2006
    Location
    Marion, Iowa
    Posts
    201
    Thanks
    0
    Thanked 13 Times in 13 Posts
    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?
    My Website: DumpsterDoggy

  • #4
    Senior Coder Arbitrator's Avatar
    Join Date
    Mar 2006
    Location
    Splendora, Texas, United States of America
    Posts
    3,300
    Thanks
    28
    Thanked 275 Times in 269 Posts
    Quote Originally Posted by PremiumBlend
    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.
    Last edited by Arbitrator; 05-01-2006 at 03:58 AM.
    For every complex problem, there is an answer that is clear, simple, and wrong.

  • #5
    Regular Coder oldcrazylegs's Avatar
    Join Date
    Feb 2004
    Location
    East Moline Illinois USA
    Posts
    414
    Thanks
    4
    Thanked 5 Times in 4 Posts
    short hex #ccc only works in css not html, xhtml or javascript

  • #6
    Regular Coder kewlceo's Avatar
    Join Date
    Mar 2006
    Location
    California, US
    Posts
    484
    Thanks
    1
    Thanked 3 Times in 3 Posts
    It's no more ambiguous than something like margin: 0 auto; IMHO.
    UBERHOST.NET
    Shared, reseller, semidedicated hosting and dedicated server plans.
    DirectAdmin • Installatron • Money-Back Guarantee • 24/7 Support
    Providing "Service Above All Else" since 2005.

  • #7
    Regular Coder PremiumBlend's Avatar
    Join Date
    Apr 2006
    Location
    Marion, Iowa
    Posts
    201
    Thanks
    0
    Thanked 13 Times in 13 Posts
    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?"
    My Website: DumpsterDoggy

  • #8
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,619
    Thanks
    0
    Thanked 645 Times in 635 Posts
    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.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #9
    Senior Coder Arbitrator's Avatar
    Join Date
    Mar 2006
    Location
    Splendora, Texas, United States of America
    Posts
    3,300
    Thanks
    28
    Thanked 275 Times in 269 Posts
    Quote Originally Posted by PremiumBlend
    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.
    For every complex problem, there is an answer that is clear, simple, and wrong.

  • #10
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,629
    Thanks
    6
    Thanked 1,002 Times in 975 Posts
    Quote Originally Posted by Arbitrator
    [...] 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.

  • #11
    Senior Coder Arbitrator's Avatar
    Join Date
    Mar 2006
    Location
    Splendora, Texas, United States of America
    Posts
    3,300
    Thanks
    28
    Thanked 275 Times in 269 Posts
    Quote Originally Posted by VIPStephan
    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.
    For every complex problem, there is an answer that is clear, simple, and wrong.

  • #12
    Regular Coder kewlceo's Avatar
    Join Date
    Mar 2006
    Location
    California, US
    Posts
    484
    Thanks
    1
    Thanked 3 Times in 3 Posts
    Quote Originally Posted by Arbitrator
    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?
    UBERHOST.NET
    Shared, reseller, semidedicated hosting and dedicated server plans.
    DirectAdmin • Installatron • Money-Back Guarantee • 24/7 Support
    Providing "Service Above All Else" since 2005.

  • #13
    Senior Coder Arbitrator's Avatar
    Join Date
    Mar 2006
    Location
    Splendora, Texas, United States of America
    Posts
    3,300
    Thanks
    28
    Thanked 275 Times in 269 Posts
    Quote Originally Posted by kewlceo
    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.
    Last edited by Arbitrator; 05-02-2006 at 09:29 PM.
    For every complex problem, there is an answer that is clear, simple, and wrong.

  • #14
    Regular Coder kewlceo's Avatar
    Join Date
    Mar 2006
    Location
    California, US
    Posts
    484
    Thanks
    1
    Thanked 3 Times in 3 Posts
    Quote Originally Posted by Arbitrator
    Because they're being lazy and not learning to use hex codes (or RGB).

    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.
    UBERHOST.NET
    Shared, reseller, semidedicated hosting and dedicated server plans.
    DirectAdmin • Installatron • Money-Back Guarantee • 24/7 Support
    Providing "Service Above All Else" since 2005.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •