test ...">
📜 ⬆️ ⬇️

Why does HTML think that chucknorris is a color?

image

Have you ever tried to set the background color in HTML using different lines? For example, the string

<body bgcolor="chucknorris"> test </body> 

will make the background of the document blood red in all browsers and on all platforms ( jsfiddle ).
')
By the way, if the word chucknorri also leads to red, then chucknorr gives yellow!

It became interesting, why is this happening? Welcome under cat.

It turns out this way since the popularity of Netscape:

Skip digits are recognized as 0 [...]. Incorrect characters are recognized as 0. So, for example, the values ​​# F0F0F0, F0F0F0, F0F0F, #FxFxFx and FxFxFx are the same.

Detailed analysis of the parsing algorithm is given here . If we apply these rules, we get the following:


So we get the following ( jsfiddle ):

image

By the way, it seems that the CSS specification was still changed, so that incorrect color names are simply ignored:

 <p><font color='chucknorris'></font></p> <p><font color='#cc0000'>   </font></p> <p><span style="color: chucknorris">!</span></p> 

PS GangnamStyle , of course, also works.
Based on Stackoverflow and Sam's Place .

Source: https://habr.com/ru/post/173727/


All Articles