Why does HTML accept color with random names / strings in the body tag?


Some time ago I read somewhere about this, but I never understood how it works: Look at the example with the word 'chucknorris': jsfiddle

Not only with the word 'chucknorris' but any random word always produces different results:

Does anyone have any explanation for this behavior?

asked by anonymous 04.09.2014 / 13:20

1 answer


This happens because all missing characters are interpreted as 0 . That is, #CC0000 equals #CCXXXX , the result will be the same, a red.

So, if we do this with the word "Earendul" the result is EA0E0D00 , which is then divided into 3 parts, being RGB (Red, Green, Blue). EA0E0D00 has 8 characters, to be divisible by 3 has to be 9. As I said earlier, when a character is missing a 0 is added. The final result would be: ( EA0 , E0D , 000 )

In other words, at the end you just have to remove the excess, with only 2 characters for each plot:

RGB( 0xEA, 0xE0, 0x00) = #EAE000

See the example in jsfiddle

04.09.2014 / 13:54