+ 12
Why does HTML interpret "elonmusk" as a color?
When using bgcolor in body tag, certain random strings produce colors: <body bgcolor="elonmusk"> Mars is red, as this page's background color </body> What's going on here? https://code.sololearn.com/WGF6pb8dBO2b/?ref=app
8 Answers
+ 34
Coloring in HTML basically takes two types of values, RGB(R, G, B - each from 0 to 255) or HEX#(RR, GG, BB each from 0 to F in hexadecimal) which can be represented interchangeably.
So, the valid alphabetical HEX values are: A, B, C, D, E, F
And keep in mind that any missing or incorrect digit in HEX base is treated as a 0.
Let's go back to what we have in this case: "elonmusk"
by the rules above the given text will be converted to: e0000000
But our HEX values are 6 digits, so it divides this value into semi-equal pieces: e00, 000, 00
Again, each color part of the HEX takes only two values: so it just trims the extra part, if any: e0, 00, 00
So, we have #e00000.
Let's see if I'm right. Take this color #a0e0f0
I'll generate random string based on this letters and the logic above. One example is: aWZepmfgg
To HEX: a00e00f00
Trim the extra parts: a0e0f0
P.S.: This is an interesting way to set colors in production code :D
+ 7
Below SO question has a detailed explanation for that behaviour:
https://stackoverflow.com/questions/8318911/why-does-html-think-chucknorris-is-a-color
+ 6
the bgcolor attribute is depreciated.Any random word thats more than 4 digits to my confusion ends up being red.spaces in texts produces color in the blue family and stuff,even i dont get this
+ 2
my name comes out puke green......LOL
+ 1
its a glitch in Matrix Mr. Anderson :-D
+ 1
Aaron Sarkissian ahh! that's the answer I was looking for when I was studying HTML body, thanks âșïžđ€ when I tried this:
bgcolor="red+blue"
0
If you are putting any word at bgcolor that contains a few hexadecimal character then that character will show you some unexpected color that you never imagine.The logical explanation behind this - during Netscape days, incorrect digits in a color code were considered as 0.
So if you apply the same rule to chucknorris
Replace all non-hex characters with 0 - you get c00c0000000
Pad out the characters so the total numbers are divisible by 3 - c00c 0000 0000
Split into 3 groups for RGB - c00c, 0000, 0000
Truncate the digits from the right to 2 characters in each color group - c0, 00, 00 (RGB).
This gives you the hex color #C00000 which is a shade of red.
http://net-informations.com/q/web/color-codes.html
0
Hi need someone to explain all HTML for me from the beginning to the end