Question:
When running a page and putting in the value of the background color an arbitrary string such as "chucknorris"
the background turns red. Why does this happen?
<body bgcolor="chucknorris">test</body>
Original question: Why does HTML think “chucknorris” is a color?
Answer:
Reference: Why does HTML think “chucknorris” is a color?
If you have invalid characters in a color code that is written in hexadecimal notation, these characters are treated as 0. A hexadecimal number can contain the characters [0-9a-f]
, any other characters found are replaced with 0
.
For chucknorris
:
- Replace invalid characters:
chucknorris
→c00c0000000
- Fill with
0
until the number of characters is divisible by 3:
c00c0000000
(11) →c00c 0000 0000
(12) - Format in RGB notation:
rgb(c00c, 0000, 0000)
- Truncate each value to two characters:
rgb(c0, 00, 00)
- Translate from hexadecimal to decimal:
rgb(192, 0, 0) [ == #C00000]
The resulting color: red.
Other similar colors: crap
, ninjaturtle
, sick
, grass
.