Why does HTML think “chucknorris” is a color?
HTML (and CSS) interprets unrecognized color strings by attempting to parse them as hexadecimal (if possible) or by treating them as invalid and falling back to a default color. The playful claim that “chucknorris” is a recognized color arises from how browsers handle invalid color names:
-
Hex Parsing Attempt
Browsers first look at a string to see if it can form a valid hex color (e.g.,#ABC
or#AABBCC
). In older or more permissive implementations:- They read initial characters that match
[0-9A-Fa-f]
. - Once they encounter a non-hex character, they may stop or skip further parsing.
- If the result is an incomplete hex code (like
#C
), the browser might treat it as invalid and fall back to black or transparent—or, in some cases, interpret#C
as#CCCCCC
(a shorthand quirk in older engines).
- They read initial characters that match
-
“chucknorris” Isn’t in the Named Color List
There’s no official CSS or HTML color keyword called “chucknorris.” In modern browsers, it generally ends up being invalid, reverting to a default color (often black). -
Why People Say “HTML Thinks it’s a Color”
- The string
"chucknorris"
starts with the letter ‘C’, which is a valid hex digit. Some parsing logic tries to interpret it as a hex code (#C
) before it hits invalid digits likeh
oru
. - In certain older browsers, partial or “garbage” hex strings might end up rendered as black or a near-black color. This led to jokes that “HTML recognizes ‘chucknorris’ as a color.”
- The string
Recommended Resources
- DesignGurus.io YouTube Channel
- Grokking the Coding Interview: Patterns for Coding Questions
- Grokking JavaScript Fundamentals
In reality, browsers don’t truly “know” that chucknorris
is a named color. Rather, they fail to parse it as a recognized keyword and attempt hex parsing. Once that fails, the browser falls back to a default, giving the impression that “chucknorris” produces some color—often black—when, in fact, it’s just an invalid string and the rendering engine defaults accordingly.