Bogus bgcolor value | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 6

Bogus bgcolor value

I incidently entered my own name in the body bgcolor attribute, and it resulted in a specific dark blue shade. It is obviously not a standard color name, also the same does not work if I put it in CSS background-color. <body bgcolor="TiborSanta"> I know we should probably not even use this attribute as it is deprecated in HTML5. But I am curious, how is this color calculated at all? https://code.sololearn.com/Wkp1me8Fqbn0/?ref=app

23rd Jun 2021, 6:24 AM
Tibor Santa
Tibor Santa - avatar
7 Answers
+ 7
visph is right but .. here is an interesting (maybe) story 😂.. i had a peek into chromium's source code to actually understand whats going on.. i couldn't post long text on q/a so .. here's it https://code.sololearn.com/Wo3ILnE9mqz6/?ref=app
23rd Jun 2021, 11:10 AM
Prashanth Kumar
Prashanth Kumar - avatar
+ 6
https://stackoverflow.com/questions/8318911/why-does-html-think-chucknorris-is-a-color
23rd Jun 2021, 6:49 AM
visph
visph - avatar
+ 4
as very permissive language, html (not css) parse unknown colors as hex values, replacing invalid 'digits' with 0... so 'TiborSanta' result as '00b000a00a', spliting in 3 parts, and getting only first 2 digits of each: "#0000a0" ;)
23rd Jun 2021, 6:43 AM
visph
visph - avatar
+ 4
visph that's what I had initially thought as well, but it doesn't seem to be the case. When replacing the values in the original string with other unknowns the color did change for me. Most commonly to a green and black.
23rd Jun 2021, 6:48 AM
ChaoticDawg
ChaoticDawg - avatar
+ 3
visph might have been a fluke (or I put a character in the wrong place, lol), it's staying the same now.
23rd Jun 2021, 6:54 AM
ChaoticDawg
ChaoticDawg - avatar
+ 2
This is curious. It seems to be only the 1st 7 characters that matter, and of course upper or lower case is irrelevant. You'll get the same result for "tiborsa". Mine "chaotic" gives a pleasing magenta like color. I would be interested to know as well how it achieves these results. I can only assume it's some type of character value overflow.
23rd Jun 2021, 6:45 AM
ChaoticDawg
ChaoticDawg - avatar
+ 2
Thank you guys. This has been fun to read through! The SO article really sheds some light on this mystery, but I award the top answer to Prashanth Kumar who did investigate the browser source code himself to arrive at the same conclusion! Well done :)
23rd Jun 2021, 6:18 PM
Tibor Santa
Tibor Santa - avatar