Member-only story
Did You Know HTML Thinks Chuck Norris Is a Color?
Weird, isn’t it? Here’s why

In every programming language, there are tricky points that are quite implausible and funny to humans but not so illogical to computers. If you have read about programming for a while, I am sure that you’ve heard many absurd concepts about JavaScript, but today we have a new guest: HTML.
What is HTML?
HTML is a markup language, specially developed for web environments. Every website you’ve seen on the internet has a markup that represents its content and hierarchy. If you want to see the markup of a website, you can simply right-click and click the Inspect. You can read more here.
What’s Going On With Color Attributes in HTML?
Since CSS has emerged, the style attributes of HTML have become outdated and deprecated one by one. However, browsers still recognize and run those attributes. Among them, bgcolor
and color
attributes are the focus of this article.
Here is a fun fact. The HTML code below is completely valid, and the output is not just a black screen — but dark red.
<body bgcolor="chucknorris"> I am valid. </body>
You may think that this is a joke hidden inside the language by its creators, just to have fun. It would be a great Easter Egg, but unfortunately, it is just the superior (!) intelligence of HTML. The bgcolor
and color
attributes expect their values to be either a color name, HEX value, or RGB value. It checks whether the value is a color name. If it’s not, it is time to check for RGB; if the value isn't that either, it should be a HEX value.
HTML is such a powerful (!) language that it automatically puts a #
before the value if you forget to do. So, both FF00FF
and #FF00FF
are the same in HTML. Moreover, it can convert any string value to HEX using an algorithm that I will explain later. Well, this whole Chuck Norris story stems from that conversion algorithm.
The Algorithm — Why Chuck Norris Is Red
In modern HTML (HTML5), bgcolor
and color
attributes are deprecated, but browsers are still able to recognize and run these attributes. These attributes normally…