Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Web Technology by (47.6k points)

How come certain random strings produce colors when entered as background colors in HTML? For example:

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

produces a document with a red background across all browsers and platforms.

Interestingly, while chucknorri produces a red background as well, chucknorr produces a yellow background.

What's going on here?

1 Answer

0 votes
by (106k points)

The reason why HTML think “chucknorris” is a color because it starts with c, and the browser reads it into a hexadecimal value.

We know that A, B, C, D, E, and F are characters in hexadecimal.

So the browser converts chucknorris to a hexadecimal value, C00C00000000. Then that hexadecimal value is converted to RGB format (after dividing by 3).

C00C00000000 => R:C00C, G:0000, B:0000

For indicating the color the browser needs only two digits to indicate the colour:-

R:C00C, G:0000, B:0000 => R:C0, G:00, B:00 => C00000

At last, it shows bgcolor = C00000 in the web browser.

Related questions

0 votes
1 answer
0 votes
1 answer
asked Aug 24, 2019 in Web Technology by Tech4ever (20.3k points)
0 votes
0 answers
0 votes
1 answer
asked Sep 4, 2019 in Web Technology by Tech4ever (20.3k points)

Browse Categories

...