Tool Guides 2 min read

Why an invalid hex code produces a dark colour instead of an error

This guide goes with the RGB & Hex Color Converter.

Open the tool

The swatch is the actual error check

An invalid hexadecimal character in the RGB & Hex Color Converter reads as zero rather than raising an error, so a mistyped code produces a dark colour instead of a warning message — the swatch shown alongside the numbers is the fastest way to notice something went wrong, since a colour that looks unexpectedly dark almost always means a typo sitting somewhere in the input.

Shorthand expansion doubles digits exactly

Three-digit shorthand is expanded by doubling each digit, so `#f0a` becomes `#ff00aa` precisely rather than approximately — which is also why only colours whose channel pairs happen to repeat can be written in the shorter form at all. `#abc` expands to `#aabbcc`, never to something like `#a0b0c0`.

Hex and RGB are the same numbers, not different levels of precision

A hex code is three pairs of hexadecimal digits, one per channel, each holding a value from 0 to 255 — identical to the values RGB expresses in base ten. Converting between the two representations is exact in both directions and loses nothing whatsoever; the choice between them comes down entirely to whatever a given piece of tooling expects to read.

A colour looking distinct is not the same as passing contrast

Two colours can appear clearly different on a screen and still fail accessibility contrast requirements when actually measured, because visual distinctiveness and a formal contrast ratio are simply not the same test. The code and the swatch here show what a colour is, not whether it works against another colour for anyone reading text set in it.

What it does not handle

Eight-digit hex codes carrying a fourth, alpha channel for transparency are not parsed here — only the standard six-digit and three-digit shorthand forms are read, so a code with transparency information will need a different tool or a manual split of the extra pair.

Try it yourself

Every tool mentioned here runs in your browser — nothing is uploaded.

Keep reading

Leave a reply

Your email address will not be published. Required fields are marked *

Subscribe to receive notifications about new tools, features, and productivity tips.