RGB to Hex Converter

Convert RGB channel values into a hex code, with shorthand where it exists.

LET’S WORK IT OUT

Your inputs

Comma separated, or paste a hex code.

Results update as you type. Check the units before you begin.

View result ↓
YOUR RESULT
—
HSV value
Adjust the inputs

Your result updates live as you type.

Going from RGB to hex is two base conversions and a join. Each channel is written as two hex digits, zero-padded, then concatenated: 29 becomes 1D, 78 becomes 4E and 216 becomes D8, giving #1D4ED8.

Values arriving as floats, percentages or 0-to-1 normalised numbers must be scaled to the 0-255 range and rounded before conversion. Rounding rather than truncating matters: 127.6 should become 80 in hex, not 7F.

The gauge shows the HSV value of the colour — the largest channel as a percentage, which is 84.7 per cent here. That is the ceiling on how bright the colour can look before you change its hue, and it is a different measure from lightness or luminance.

The formula

hex = # + pad(R16) + pad(G16) + pad(B16)
R, G, B
Channel values, 0 to 255
pad
Zero-fill to two digits, so 5 becomes 05
V
HSV value: max(R, G, B) ÷ 255
shorthand
Available only when both digits of every pair match

How to use this calculator

  1. Type the three channel values separated by commas.
  2. Values outside 0 to 255 are clamped, and decimals are rounded.
  3. Copy the hex code from the first result.
  4. The shorthand line tells you whether a three-digit form exists.

Worked examples

The default triple

rgb(29, 78, 216) becomes #1D4ED8. No pair has matching digits, so there is no shorthand. HSV value is 84.7 per cent because blue sits at 216.

When shorthand exists

rgb(255, 204, 0) becomes #FFCC00, and because every pair repeats it shortens to #FC0. That saves three characters and is the reason so many palettes gravitate to multiples of 17, since 17 x 15 = 255.

How to read your score

0–25Very darkNo channel rises above a quarter of full scale.
25–50DarkDeep colour with limited headroom.
50–80MidThe usual range for brand and body colours.
80–—BrightAt least one channel is near maximum.

Frequently asked questions

What if my values are 0 to 1?

Multiply by 255 and round. A value of 0.5 becomes 128, written 80 in hex. Graphics APIs and shader code commonly use the normalised form.

Which colours have a three-digit shorthand?

Only those where each channel is a multiple of 17 — 0, 17, 34 and so on up to 255. That is 16 values per channel, so 4,096 colours out of 16.7 million.

Should I round or truncate a fractional channel?

Round. Truncating drags every channel down by up to one step, which shifts hue slightly and darkens gradients in a way that shows up as banding.

Does hex support percentages?

No. Percentage notation only exists in the rgb() and hsl() functional forms. Hex is always an integer 0 to 255 per channel.

Why does my design tool show a fourth pair?

That is the alpha channel. Strip the last two digits if the destination only accepts six, and set opacity separately.

RGB triples converted to hex

Named CSS colours with their hex form
ColourRGBHexShorthandHSV value
Tomato2559971#FF6347—100%
Slate blue10690205#6A5ACD—80%
Sea green4613987#2E8B57—55%
Goldenrod21816532#DAA520—85%
Steel blue70130180#4682B4—71%
Indian red2059292#CD5C5C—80%
Dark slate grey477979#2F4F4F—31%
Gainsboro220220220#DCDCDC—86%

Shorthand exists only where both digits of every hex pair match.

Related calculators