Ein Hex-Farbcode wird in seine Rot-, Grün- und Blauanteile umgerechnet, mit einer Farbfläche und einer fertig einfügbaren CSS-Deklaration.
Ein Hex-Code besteht aus drei Paaren hexadezimaler Ziffern, eines je Kanal, jedes mit einem Wert von 0 bis 255. Die dreistellige Kurzform wird zuerst expandiert, indem jede Ziffer verdoppelt wird — aus #f0a wird also #ff00aa. Diese Expansion ist exakt, und genau deshalb gibt es die Kurzform. Fehlt die führende Raute, wird sie ergänzt statt als Fehler behandelt. Alles, was kein gültiges Hexadezimalpaar ist, wird als null gelesen; ein fehlerhafter Code erzeugt daher eine dunkle Farbe statt einer Warnung, und die Farbfläche ist der schnellste Weg, das zu bemerken.
Mit Farbwerten arbeiten
-
Die Farbfläche ist die Fehlerprüfung:
Ein ungültiger Code wird als null geparst statt zu scheitern; eine Farbe, die falsch aussieht, deutet daher meist auf einen Tippfehler in der Eingabe hin.
-
Die Kurzform-Expansion verdoppelt Ziffern:
#abc ist #aabbcc, nicht #a0b0c0. Nur Farben, bei denen sich die Ziffern jedes Kanalpaars zufällig wiederholen, lassen sich überhaupt in der Kurzform schreiben.
-
Hex und RGB sind dieselben Zahlen:
Das eine steht zur Basis sechzehn, das andere zur Basis zehn. Keines ist genauer; nehmen Sie das, was Ihre Werkzeuge erwarten.
-
Der Kontrast ist im Code nicht sichtbar:
Zwei Farben können auf Ihrem Bildschirm deutlich verschieden wirken und die Kontrastanforderungen der Barrierefreiheit dennoch verfehlen. Prüfen Sie das Verhältnis, statt der Farbfläche zu vertrauen.
The swatch is the actual error check
An invalid hexadecimal character in the [msm_tool slug="rgb-hex-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.