Developer 🔒 Runs in your browser — no data sent to servers

RGB to HEX Converter

Enter red, green and blue values or a CSS rgb() string and get the matching HEX color code.

Input Color
Enter a color to convert...

Convert RGB Colors to HEX Codes

Color pickers, image editors and graphics code often report colors as three numbers, while CSS, design tokens and brand guidelines prefer the compact HEX code. Converting RGB to HEX is exact: the same three bytes are simply written in base 16.

This page opens the Color Converter with RGB input selected and an example filled in.

Diagram: the HEX colour #0A84FF split into the pairs 0A, 84 and FF, which are 10, 132 and 255 in decimal: rgb(10, 132, 255), or hsl(210, 100%, 52%).#R0A10G84132BFF255Two hex digits per channel0x84 = 8 × 16 + 4 = 132Each channel runs from 0 to 255rgb(10, 132, 255)hsl(210, 100%, 52%)
A HEX colour is three pairs of hexadecimal digits for red, green and blue. #0A84FF is rgb(10, 132, 255), and the very same colour written in HSL is hsl(210, 100%, 52%).

The conversion step by step

  1. Take each channel value from 0 to 255.
  2. Divide by 16: the whole number is the first hex digit, the remainder the second (10 to 15 are written A to F).
  3. Pad single digits with a leading zero, so 10 becomes 0A, not A.
  4. Join the three pairs after a #.
RGBPer channelHEX
rgb(10, 132, 255)0A · 84 · FF#0A84FF
rgb(255, 87, 51)FF · 57 · 33#FF5733
rgb(128, 128, 128)80 · 80 · 80#808080

Forgetting the zero padding is the classic bug in hand-written converters: 10, 132, 255 joined without padding gives #A84FF, which is not a valid color.

rgba() and 8-digit HEX

CSS has accepted 8-digit HEX codes for years. The fourth pair is alpha: multiply the 0–1 alpha by 255 and round, so 0.5 becomes 128, or 80 in hex. The converter shows both the 8-digit code and the rgba() form, so you can use whichever your tool supports.

RGB to HEX in code

In JavaScript: '#' + [r, g, b].map(v => v.toString(16).padStart(2, '0')).join(''). In Python: '#{:02X}{:02X}{:02X}'.format(r, g, b). Both handle the zero padding for you.

Related tools

Use HEX to RGB for the reverse direction, HEX to HSL when you want to adjust lightness systematically, and the Color Contrast Checker before using a color for text.