DEV Community

Sam-Sundar
Sam-Sundar

Posted on

Why does HTML recognize Ninja Turtle as a Background Colour

Why do certain random strings produce colours when entered as background colours in HTML
For example, Look at the following code snippet and its output

<html lang="en">


<head>
  <title>Hello, world!</title>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width,initial-scale=1" />
  <meta name="description" content="" />
</head>
<body bgcolor="ninjaturtle">
  <h1 >What should you do when you see a green alien</h1>
  <h1>Wait until it's ripe</h1>
</body>
</html>

Enter fullscreen mode Exit fullscreen mode

And now let's look at the output

green alien

green alien 2

The real reason behind this is that the browser can not understand it and tries to somehow translate it to what it can understand and in this case turns it into a hexadecimal value

ninja turtles start with n which is an unrecognized character in hexadecimal, also it's converting all unrecognized characters into 0

However, it recognizes all the hexadecimal characters and keeps it as it is

So ninja turtles in hexadecimal format becomes:0000a00000e0 and all other characters become 0 other than a and e remain where they are...

Now they get divided by 3 for RGB(red, green, blue)... R: 0000, G: a000, B:00e0...

But we know valid hexadecimal for RGB is just 2 characters, which means R: 00, G: a0, B:00
.

So the real result is:
<body bgcolor="#00a000">

There are other anomalies as well

<body bgcolor="cabs">
<h1>
  Fun fact - According to this logic  bgcolor="cabs" test 
  would give you the color of a California Taxi Cab
  </h1>
</body>
Enter fullscreen mode Exit fullscreen mode

produces

cab

Also Netscape(RIP) was located in Mountain View,California

and one final one for all my pokemon lovers

<table>
  <td bgcolor="squirtle">squirtle</td>
  <td bgcolor="ivysaur">ivysaur</td>
  <td bgcolor="charmeleon">charmeleon</td>
</table>
Enter fullscreen mode Exit fullscreen mode

pokemon
you can read about more HTML anomalies at: A little rant about Microsoft Internet Explorer's color parsing

Thanks for Reading

Top comments (0)