Why does HTML think “chucknorris” is a color? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 7

Why does HTML think “chucknorris” is a color?

How come certain random strings produce colors when entered as background colors in HTML? For example: ///////// <body bgcolor="chucknorris"> test </body> //////// ...produces a document with a red background across all browsers and platforms. Interestingly, while "chucknorri" produces a red background as well, "chucknorr" produces a yellow background. What's going on here? 😂

22nd Jul 2017, 8:31 AM
Ahmed Omer Soliman Altayeb
Ahmed Omer Soliman Altayeb - avatar
4 Answers
+ 25
While parsing colors, invalid digits are considered as 0. So, chucknorris => c00c0000000 This is divided to 3 parts (r, g, b). So, chucknorris => c00c 0000 000 Only the first two digits are considered. So, chucknorris => c0 00 00 And, RGB(c0, 00, 00) is RED. I think you can get why chucknorr => yellow now.
22nd Jul 2017, 8:41 AM
Krishna Teja Yeluripati
Krishna Teja Yeluripati - avatar
+ 8
This only work with 'bgcolor' and other depecrated html attributes: this is not the behaviour for Css color declaration, which ignore invalid names... This is due to the permissivity of Html specifications which intend browsers to display invalid document as well as they can, by auto correcting invalid Html... So the value set to a deprecated styling attribute will be converted at parse time to a css style declaration and invalid values are also tried to be displaying as much as possible (Css specifications are not as much permissive for invalid values) ^^
22nd Jul 2017, 9:39 AM
visph
visph - avatar
+ 5
Because Chuck Norris, duh 😂
22nd Jul 2017, 12:05 PM
Matthew Wong
Matthew Wong - avatar
+ 1
Just stumbled across this. This is a very interesting feature of HTML...
4th Jul 2020, 6:04 AM
Frenchtoast
Frenchtoast - avatar