RGB to HEX

Convert RGB to HEX colors.

Output appears here.

This is the mirror image of the more famous hex-to-RGB conversion: you supply three numbers between 0 and 255 — the amount of red, green and blue light a pixel emits — and get back the packed six-digit code that CSS, HTML and most design tools expect.

RGB: a model borrowed from human vision, not computers

The red-green-blue additive model didn't originate with computing at all. It traces to 19th-century research into human trichromatic vision by Thomas Young and Hermann von Helmholtz, who proposed that the eye perceives color through three types of receptors roughly sensitive to red, green and blue wavelengths. Television engineers adopted the same three-channel logic for the NTSC color standard in 1953, and when raster computer displays arrived decades later, they inherited RGB directly because it matched how a CRT's phosphors and, later, an LCD's sub-pixels physically emit light.

The math behind the conversion

Each channel (0–255) is converted independently to a two-digit hexadecimal number, then the three pairs are concatenated with a leading #. The conversion is exact and lossless in both directions — nothing is rounded or approximated, since 255 in decimal is precisely FF in hex, so RGB↔hex is purely a change of notation, not a change of color.

Common situations where you need RGB→hex

  • Reading values off a physical color sensor or camera API, which typically reports RGB integers, then needing a hex value to paste into CSS.
  • Extracting a color from an image using a canvas getImageData call (which returns RGB/RGBA), then wanting a shareable hex code for a style guide.
  • Working from a printed Pantone-to-RGB conversion chart supplied by a brand guideline, and needing the web-ready hex equivalent.

Frequently asked questions

What if I enter a value above 255? RGB channels are clamped to the 0–255 range because that's the maximum a single byte (8 bits) can represent — it's the same limit that gives 24-bit color its "16.7 million colors" figure (256 × 256 × 256).

Can I convert RGBA (with transparency)? Yes — a fourth alpha value converts to the two extra digits of an 8-digit hex color, standardized in CSS Color Level 4.

Why do designers prefer hex but developers sometimes prefer RGB? Hex is compact for storing and copying a single color; RGB's separated channels are easier to manipulate programmatically — for example lightening a color by adding to all three channels at once.

Further reading