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
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
- Type the three channel values separated by commas.
- Values outside 0 to 255 are clamped, and decimals are rounded.
- Copy the hex code from the first result.
- 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
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
| Colour | R | G | B | Hex | Shorthand | HSV value |
|---|---|---|---|---|---|---|
| Tomato | 255 | 99 | 71 | #FF6347 | — | 100% |
| Slate blue | 106 | 90 | 205 | #6A5ACD | — | 80% |
| Sea green | 46 | 139 | 87 | #2E8B57 | — | 55% |
| Goldenrod | 218 | 165 | 32 | #DAA520 | — | 85% |
| Steel blue | 70 | 130 | 180 | #4682B4 | — | 71% |
| Indian red | 205 | 92 | 92 | #CD5C5C | — | 80% |
| Dark slate grey | 47 | 79 | 79 | #2F4F4F | — | 31% |
| Gainsboro | 220 | 220 | 220 | #DCDCDC | — | 86% |
Shorthand exists only where both digits of every hex pair match.