Results 1 to 4 of 4

Thread: Hex Color Question

  1. #1
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default Hex Color Question

    I understand the hexadecimal number set... 0-15 becomes 0-9 and A-F, and I understand that hex color codes work like #RRGGBB and the hex number correlates to the appropriate color intensity, but my question is this:

    Why do these present different colors? #A60000 and #6A0000

    Code:
    <div style="background: #A60000; ">test</div>
    <div style="background: #6A0000; ">test</div>
    - Mike

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Because they're two different numbers.

    The 2 digit hex code for any of the three rgb colors can be 00 to ff, or in decimal a potentially 3 digit number from 0 to 255.

    The hex code is like you say rrggbb, so it's really three different 2 digit numbers in base 16. Converted to decimal rgb notation (also valid for css style color values), you would have:

    #a60000 or rgb(166, 0, 0)

    and:

    #6a0000 or rgb(106, 0, 0)

    See, two different numbers.

    You can play with it yourself. Fire up Calculator. From the view menu choose 'Programmer'. Tick off hex, then enter a6. Then tick off decimal, you get 166. You can do the same with any numbers you like.

    But basically a hex color value like #a60000 means - red hex a6, green hex 0, and blue hex 0.
    Last edited by jscheuer1; 03-03-2012 at 01:09 AM. Reason: two missing commas
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. The Following User Says Thank You to jscheuer1 For This Useful Post:

    mburt (03-13-2012)

  4. #3
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Also note that some of the confusion in this comes from the odd way that the web tends to accept invalid 3-digit hex colors like #ABC or #123, where those actually represent #AABBCC and #112233. The way the web works (or worked about 10? 15? years ago) is by expecting "web safe colors" that can be represented on all systems. So in theory you're supposed to use the same values for the two digits for each color (#RRGGBB), but in reality that's silly now. If you can use an image in your website, then there's no reason to avoid other colors in your websites. Of course if you want you can use the 3-digit shortcut, but as far as I know that was never the intent of the system (even if you don't use differing values between the two digits).
    Last edited by djr33; 03-15-2012 at 04:38 AM.
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  5. The Following User Says Thank You to djr33 For This Useful Post:

    mburt (03-13-2012)

  6. #4
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

Bookmarks

Posting Permissions

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