RGB to HEX Converter
Convert RGB values into a HEX color code, with a live swatch preview.
Each channel becomes two hex digits
A hex colour code is the red, green and blue values written in base 16, two digits each. To convert a channel, divide it by 16. The whole-number result is the first digit and the remainder is the second, where 10 through 15 are the letters a through f. For rgb(255, 87, 51):
| Channel | Value | ÷ 16 | Remainder | Hex |
|---|---|---|---|---|
| Red | 255 | 15 (f) | 15 (f) | ff |
| Green | 87 | 5 | 7 | 57 |
| Blue | 51 | 3 | 3 | 33 |
Put them together in order and you get #ff5733, the same code the converter shows.
Entering your RGB values
Type the numbers into the separate R, G and B boxes. The RGB field above them is a read-only result, so pasting rgb(255, 87, 51) as text won't work. Enter the three numbers one by one.
Each box keeps its value between 0 and 255 and rounds decimals:
- 300 becomes 255 and −4 becomes 0
- 12.6 becomes 13
- an empty box counts as 0
The HEX result is always six lowercase digits with a #. Small values keep their leading zero, so rgb(9, 10, 11) gives #090a0b. Dropping those zeros is a common mistake when converting by hand, and it produces a different colour or an invalid code.
Short codes and transparency
CSS also accepts 3-digit codes, but only when each pair repeats: #ff8800 can be written #f80, while #ff5733 has no short form. The converter always gives the full six digits, which work everywhere.
If your colour has an alpha value, as in rgba(255, 87, 51, 0.5), enter only the red, green and blue numbers. The page has no alpha channel, so the result is the solid colour. Keep the rgba() form, or add transparency separately where you use the colour.
Frequently asked questions
What is rgb(0, 0, 0) in hex?+
#000000, which is black. rgb(255, 255, 255), white, is #ffffff.
My values are percentages. How do I enter them?+
Multiply each percentage by 2.55 and type the result. 50% is 127.5, which the box rounds to 128, shown in hex as 80.
Does the order of the numbers matter?+
Yes. The order is always red, green, blue. Swapping red and blue in rgb(255, 87, 51) gives rgb(51, 87, 255), which is #3357ff, a blue instead of an orange-red.
Can I convert a hex code back to RGB on the same page?+
Yes. Type or paste the code into the HEX box and the R, G and B boxes fill in with its channel values, along with the RGB and HSL text.
Embed this tool on your website
Free to use on blogs, school sites and intranets. Paste this code into your page's HTML; please keep the credit line.
<iframe src="https://utilityapp.lat/embed/convert/rgb-to-hex" title="RGB to HEX Converter" width="100%" height="520" style="border:0;max-width:760px" loading="lazy"></iframe> <p style="font-size:13px"><a href="https://utilityapp.lat/convert/rgb-to-hex">RGB to HEX Converter</a> by UtilityApp</p>