Comment utiliser cette calculatrice
What the two notations mean
Hex and rgb() are two spellings of the same thing: three channel values that say how much red, green, and blue a color mixes. A hex code like #3498db is the three channels written in base 16 — the pairs 34, 98, db — while rgb(52, 152, 219) writes the same numbers in decimal. The converter is pure arithmetic on those channels: each hex pair is parsed with parseInt(·, 16) and each decimal channel is converted back to two base-16 digits, so the two forms are always exact, never approximated.
That is the tool’s entire job, and it is why the conversion is instant and lossless: #3498db is rgb(52, 152, 219), and rgb(52, 152, 219) is #3498db, with nothing lost in either direction. The hex form is the compact notation style guides and design systems use; the rgb() form is what many charting libraries, canvas APIs, and older CSS code expect.
The input forms that just work
Values copied out of a browser inspector, a design tool, or a mockup arrive in different shapes, and the converter accepts them as pasted: a 6-digit code, a 3-digit shorthand like #fff (which expands to #ffffff, matching CSS behavior), an optional leading #, uppercase or lowercase digits, and even the full function syntax rgb(52, 152, 219) or a bare triplet 52, 152, 219. Output is always normalized to the unambiguous 6-digit lowercase hex form, so the result never carries the ambiguity of shorthand.
Validation is strict about what a color can be: hex digits must be valid hex, and each RGB channel must be an integer from 0 to 255. A triplet with a channel of 300 is rejected with a clear message rather than silently clamped — CSS clamps out-of-range values, but a conversion tool should not invent a color the input did not describe.
Why the precedence rule exists
When both fields are filled, the hex value wins and converts to RGB; the rgb field is ignored. The rule is documented rather than guessed because a converter that silently picked a side would produce a result that disagreed with what the user intended to change. The behavior is predictable: edit the field you want to be authoritative, and the other side updates to match.
The same predictability applies to case and formatting: hex output is always lowercase because hex digits are case-insensitive and lowercase is the convention most tooling and minifiers use, and shorthand input always expands to the full form so the result is unambiguous.
The honest limits
The converter handles three-channel colors only: 4- and 8-digit hex (#rgba, #rrggbbaa) and rgba() carry an alpha channel this tool does not parse, and named CSS colors (red, blue, rebeccapurple) are not accepted — convert those by looking up their hex or rgb form first. For colors with transparency, convert the 6-digit base color here and keep the alpha separately. And as with everything on the site, the conversion runs entirely in your browser: no value you enter is uploaded, logged, or stored.
Questions fréquentes
Quelle est la différence entre le hex à 3 et à 6 chiffres ?
Un code à 3 chiffres comme #fff est la forme courte de CSS : chaque chiffre est doublé, donc #fff signifie #ffffff. Tout navigateur moderne l’accepte. Le convertisseur accepte les deux et émet toujours la forme complète à 6 chiffres, pour que le résultat soit sans ambiguïté.
Gérez-vous les valeurs alpha (transparence) ?
Pas encore. Le hex à 8 chiffres (#rrggbbaa) et rgba() portent un canal de transparence que ce convertisseur n’interprète pas. Pour les couleurs avec alpha, convertissez ici la couleur de base à 6 chiffres et conservez l’alpha séparément.
Pourquoi la sortie hex est-elle en minuscules ?
Les chiffres hex ne distinguent pas la casse — #3498db et #3498DB sont la même couleur. Les minuscules sont la convention de la plupart des outils et minificateurs modernes, et maintiennent une sortie cohérente pour le copier-coller.
Que se passe-t-il si je remplis les deux champs hex et RGB ?
Le hex l’emporte et se convertit en RGB ; le champ RGB est ignoré. L’outil documente cette précédence plutôt que de deviner, donc le résultat est toujours prévisible.
Why is #fff the same color as #ffffff?
CSS 3-digit shorthand doubles each digit: #fff means #ff ff ff, which is exactly #ffffff. The converter accepts both and always outputs the expanded 6-digit form, so the result is unambiguous.
Is 300, 0, 0 ever a valid color?
No — each channel must be an integer from 0 to 255. CSS clamps out-of-range values silently; this converter rejects them with an error instead, because converting a value that was not a color would produce a misleading result.