Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Why does HTML think 'Chucknorris' is a color?

    • 0
    • 1
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 153
    Comment on it

    Hey there!

    So this is a really interesting topic I came across yesterday. And immediately thought of sharing it with you all.

    In CSS, we are giving colors in RGB format or hexadecimal format. But what if you came to know that HTML accepts any random string of words as colors?

    Yes, this is true. At first even I thought the whole of HTML And CSS were crazy!

    As according to the title of this blog post, it has nothing to do particularly with "chucknorris". Tomato, London, and even BarackObama are valid CSS color names.

    So, what's actually going on here?

    Here is the logical explanation behind this.

    Back in the Netscape days, missing or incorrect digits were simply interpreted as 0.

    For example, values like #F0F0F0, F0F0F0, F0F0F, #FxFxFx and FxFxFx are all same. That is all about it. Then, there are some rules according to which the strings are considered as colors.

    Now, applying the same rules to "chucknorris", let us see what color does this produce.

    1. Replace all non-hexadecimal characters with 0.  We get c00c0000000.
    2. Pad out the next total number of characters that is divisible by 3 - c00c 0000 0000
    3. Split the whole into 3 equal groups for RGB - c00c, 0000, 0000
    4. Truncate the digits from the right down to 2 characters in each group - c0, 00, 00 (RGB).

    We get the final result :

    RGB (c0, 00, 00)

    or

    RGB (192, 0, 0)

    which is a shade of red.

    You can read about this fun thing in more detail at http://scrappy-do.blogspot.in/2004/08/little-rant-about-microsoft-internet.html .

     

    Try out with random strings that come to your mind.

     

    Happy Coding :)

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: