How RGB to hex conversion works
Each channel is a number from 0 to 255, which fits exactly in two hexadecimal digits. Convert to base 16 and pad to two characters: 255 gives FF, 87 gives 57 (87 = 5x16 + 7) and 51 gives 33. Joining them in red-green-blue order with a leading hash produces #FF5733. Values below 0 or above 255 are clamped, and decimals are rounded to the nearest whole number.
Once you are done here, the RGB to HSL converter picks up where this leaves off.
How to use this converter
Enter the three channel values from a design tool, a screenshot picker or a CSS rgb() declaration. The result is shown in uppercase, with the lowercase form in the note beneath - both are valid CSS and the choice is purely a style convention. To read an existing code back into channels, use the hex to RGB converter.
Rounding matters when the source uses percentages or floats: rgb(127.5, 0, 0) rounds to 128 and becomes #800000. Nothing is uploaded — the conversion runs in your browser as you type.
Quick conversion table
Common channel values and their hex pairs:
| Decimal | Hex |
|---|---|
| 0 | 00 |
| 51 | 33 |
| 87 | 57 |
| 128 | 80 |
| 204 | CC |
| 255 | FF |
The same base conversion is covered by the decimal to hex calculator.
Worth memorising: #000000 is black, #FFFFFF is white, and any code with three equal pairs such as #808080 is a neutral grey. If red, green and blue are all within a few points of each other the colour will read as grey on screen no matter how it looks in your editor.
Frequently asked questions
- What is rgb(255, 87, 51) in hex?
- It is #FF5733, formed from FF for red, 57 for green and 33 for blue.
- Does uppercase or lowercase hex matter?
- No. CSS treats #ff5733 and #FF5733 identically, so pick whichever your codebase already uses.
- What happens if I enter a value above 255?
- It is clamped to 255, since that is the maximum a single 8-bit channel can hold.
- Can I shorten the result to three digits?
- Only when each pair repeats, such as #FFCC00 becoming #FC0. #FF5733 cannot be shortened.
- Can I convert an rgba() colour with transparency?
- Not with a six-digit hex code, which carries only red, green and blue. Convert the three colour channels here, then add the alpha as two extra hex digits (#FF573380 is 50% opacity) if your browser targets support eight-digit hex.