RGB to HEX Converter
RGB to HEX turns three decimal channels into a hex colour. Each channel is divided by 16: the quotient is the first hex digit and the remainder is the second, so 136 becomes 88 and 255 becomes ff. An alpha value is appended as a fourth pair, rounded to the nearest of 256 steps — which is the one place the round trip is not exact.
Enter a colour on the left. This accepts hex with or without the hash, rgb(), hsl(), oklch() and the CSS colour names.
How does RGB to HEX Converter work?
Each channel is a whole number from 0 to 255, and two hex digits hold exactly that range. Divide by 16: the quotient is the first digit, the remainder is the second. 136 ÷ 16 is 8 remainder 8, so 88. 255 ÷ 16 is 15 remainder 15, and 15 is f, so ff.
Single-digit channels need the leading zero
A channel below 16 produces one digit, and dropping the zero shifts every digit after it. rgb(255 8 0) is #ff0800, not #ff800 — the second of which is five digits and not a colour at all. It is the classic bug in a hand-rolled converter, and it only shows up on dark colours, which is where nobody looks.
What happens to a non-integer channel
CSS allows rgb(255.6 136 0), and hex cannot hold a fraction. The value is rounded to the nearest integer, which is what the browser does too. If your channels came out of a calculation — a lightened colour, an interpolated step — the hex you get back is the rounded version, and converting it forward again will not return the fraction you started with.
Alpha, and the one lossy step
An alpha of 0.5 becomes 80, because 0.5 × 255 is 127.5 and it rounds to 128. Converting that back gives 0.502. Every colour channel round-trips exactly; alpha does not, because it is a fraction being stored in 256 steps. The difference is far below anything visible and it will show up the moment you compare two strings in a test.
Percentages
rgb(100% 53.3% 0%) is the same colour as rgb(255 136 0): percentages in rgb() resolve against 255, not against 100. This catches people converting from a design tool that exports 0–100 values, where 53% means 135, not 53.
RGB channels
rgb(255 136 0)
The hex colour
#ff8800 255 → ff (15 × 16 + 15) 136 → 88 (8 × 16 + 8) 0 → 00 (0 × 16 + 0)
What options and edge cases does RGB to HEX Converter support?
| Parameter | Type | Default | Behaviour & edge cases |
|---|---|---|---|
| 0 | channel | 00 | The minimum. Both digits zero. |
| 8 | channel | 08 | Below 16, so the leading zero is required. Dropping it corrupts the whole value. |
| 128 | channel | 80 | The midpoint, and 8 × 16 exactly. |
| 136 | channel | 88 | 8 × 16 + 8. |
| 255 | channel | ff | The maximum. 15 × 16 + 15. |
| 0.5 alpha | fraction | 80 | 127.5 rounds to 128. Converting back gives 0.502 — the only step of this conversion that is not exact. |
| 255.6 | non-integer | ff | Rounded, as the browser rounds it. A fractional channel cannot survive hex. |
| 100% | percentage | 255 | Percentages resolve against 255. 53% is 135, not 53. |
Frequently asked questions
How do I convert RGB to hex manually?
Divide each channel by 16. The quotient is the first digit and the remainder is the second, with 10–15 written as a–f. 136 ÷ 16 = 8 remainder 8, so 88. Write the three pairs in order — red, green, blue — with a # in front. The only trap is a channel below 16: it must still be two digits, so 8 is 08, not 8.
Why is my hex colour five digits long?
A channel under 16 lost its leading zero. rgb(255 8 0) is #ff0800; written as #ff800 it is five characters, which is not a valid hex colour and browsers will ignore the whole declaration. This is the most common bug in hand-written conversion code and it only appears on dark colours.
Does converting RGB to hex lose any colour information?
No, for the colour itself — both notations hold the same three bytes, so the round trip is exact. Alpha is the exception: it is a fraction in CSS and hex stores it in 256 steps, so 0.5 becomes 80 and comes back as 0.502. Invisible on screen, visible in a string comparison.
What does rgb(100% 50% 0%) convert to?
#ff8000. Percentages in rgb() are fractions of 255, not of 100, so 50% is 127.5 which rounds to 128 — hex 80. If a design tool exported those numbers as 0–100 values they mean something different, and that mismatch is worth checking before pasting.
Should I write rgba() or use an 8-digit hex?
Either; both are supported everywhere current. 8-digit hex is more compact and keeps the whole colour in one token, which suits design tokens and variables. rgba() is easier to read and easier to edit by hand, and it is what most existing stylesheets already contain. The only real argument is consistency with the code around it.
Why does a designer's hex not match the RGB my screen picker reports?
Colour management. A screen picker samples pixels after the display profile has been applied, so a wide-gamut monitor reports different numbers for the same sRGB source colour. Sample from the design file rather than from a screenshot, or set the picker to sRGB, and the two agree again.
Which related tools should I use next?
- Color ConverterConvert between HEX, RGB, HSL, HSV, OKLCH and CMYK, in both directions at once.
- HEX to RGB ConverterTurn a hex colour into its rgb() values, including the alpha channel from an 8-digit hex.
- HEX to HSL ConverterTurn a hex colour into hue, saturation and lightness, ready to paste into CSS.
- HSL to HEX ConverterTurn hue, saturation and lightness into a hex colour.