Why do weird things in font color attribute produce real colors? [duplicate]
The HTML 5 specification includes the rules for parsing legacy colours.
They are rather long, and are designed to allow browsers to be consistent about how they handle broken code.
Very interesting. Seems as though the browser will interpret any character it can (a-f) and leave the rest to be 0's if it can't match. For instance:
Spiderman
00DE0 A
Still needs more experimenting though.
This is an intriguing question.
Through brief experimentation, I've found that "Luck" produces the same color (to my eyes, anyway) as "LuckyCharms" but "LuckBeALady" gets you a darker shade, while "LuckBeALadyTonight" is bluer.
BTW, my first thought was that it was acting on the recognizable hex characters, but that turns "LuckyCharms" into cca, which rendered black. Combinations of 0's and the hex chars, as Madara Uchiba suggests, failed to render the same grass green as "LuckyCharms"
Don't have an answer tho.
The basic answer for what is expected to happen is "it depends on the browser". One of the problems with previous versions of HTML before 5 is that it is unspecified what happens when non-standard HTML is encountered by the browser. The interpretation from @Madara Uchiha is one example of how a browser might interpret the color specification, but it's just as allowable, standards-wise, for the browser to crash or to eject the CD tray or to change the resolution of your monitor to 400x300 px. Of course, this is not ideal - so what you're seeing is one programmer's idea, at one time, as to what should happen if a non-standard HTML color specification is encountered.
The reason it doesn't happen with CSS is that it's a different parser interpreting the color. This same parser interprets the color whether it's inline CSS or in a linked-in CSS document. CSS does define what happens to an improper value when it is encountered: it is ignored, and does not affect the document at all.
I would say this is a good time to talk to the class about standards compliance, as this is a critical field of understanding for students - and some professionals I have the misfortune to know. When they say, "But color Skittles works just fine", you can tell them that it works fine when they look at it, but it's entirely possible that it would crash their instructors' browser, earning them a big fat F. That's as close to a real-world scenario as you can get, when some of us have to give up our weekends because at demo time somebody else's crappy code doesn't work correctly.
I ain't bitter though. Mostly :)