RGB to HEX Converter
RGB in, HEX color code out — with the working shown.
To convert RGB to HEX, take each channel, convert to base 16, then pad and join. For example, rgb(47 129 247) in RGB is #2f81f7 in HEX.
This is a free RGB to HEX converter. Type or paste any red, green and blue channel values into the field above and the HEX value updates as you type, along with every other notation the web understands. HEX is a six-digit hexadecimal number, two digits per channel, written with a leading #.
Conversions run entirely in your browser using the same color engine as the rest of the site: values round-trip through linear sRGB and CIE XYZ rather than through an approximation, so what you copy is accurate to the last digit the format can carry.
How to convert RGB to HEX
- Take each channel. Round each of the red, green and blue values to a whole number between 0 and 255.
- Convert to base 16. Divide by 16 for the first digit and take the remainder for the second, writing 10–15 as a–f.
- Pad and join. Pad any single digit with a leading zero, join the three pairs in order and prefix a #.
Worked example: rgb(47 129 247) converts to #2f81f7. That color is Dodger Blue, and the tool above shows each intermediate step for whatever value you enter.
Common RGB to HEX values
The twenty colors people look up most often, converted from RGB to HEX. Every row is computed by the same engine as the tool above.
| Color | RGB | HEX |
|---|---|---|
| White | rgb(255 255 255) | #ffffff |
| Black | rgb(0 0 0) | #000000 |
| Red | rgb(255 0 0) | #ff0000 |
| Lime | rgb(0 255 0) | #00ff00 |
| Blue | rgb(0 0 255) | #0000ff |
| Yellow | rgb(255 255 0) | #ffff00 |
| Cyan | rgb(0 255 255) | #00ffff |
| Magenta | rgb(255 0 255) | #ff00ff |
| Silver | rgb(192 192 192) | #c0c0c0 |
| Gray | rgb(128 128 128) | #808080 |
| Maroon | rgb(128 0 0) | #800000 |
| Olive | rgb(128 128 0) | #808000 |
| Green | rgb(0 128 0) | #008000 |
| Purple | rgb(128 0 128) | #800080 |
| Teal | rgb(0 128 128) | #008080 |
| Navy | rgb(0 0 128) | #000080 |
| Orange | rgb(255 165 0) | #ffa500 |
| Pink | rgb(255 192 203) | #ffc0cb |
| Gold | rgb(255 215 0) | #ffd700 |
| Crimson | rgb(220 20 60) | #dc143c |
RGB and HEX, briefly
RGB is three channels from 0 to 255 describing how hard the display drives its red, green and blue subpixels. Valid range: 0–255 per channel.
HEX is a six-digit hexadecimal number, two digits per channel, written with a leading #. Valid range: #000000 to #ffffff.
Frequently asked questions
How do you convert RGB to HEX?
1. Round each of the red, green and blue values to a whole number between 0 and 255. 2. Divide by 16 for the first digit and take the remainder for the second, writing 10–15 as a–f. 3. Pad any single digit with a leading zero, join the three pairs in order and prefix a #. The converter on this page does all of it as you type, and shows the working underneath.
What is rgb(255 0 0) in HEX?
Pure red, rgb(255 0 0), is #ff0000 in HEX. There is a table of twenty common colors converted to HEX further up this page.
What is rgb(47 129 247) in HEX?
rgb(47 129 247) converts to #2f81f7. It is a dodger blue, and you can paste any other value into the field at the top of the page to convert it.
Is RGB to HEX conversion lossless?
Within sRGB, yes — converting to HEX and back returns the value you started with. The only rounding happens when a component is written out to a fixed number of decimal places.
Can I use HEX directly in CSS?
Yes. #2f81f7 is valid CSS and works in every current browser.
Does this RGB to HEX converter support transparency?
Alpha is preserved wherever the target notation can carry it — eight-digit hex, rgb() / a, hsl() / a and the modern CSS spaces all round-trip an alpha channel. CMYK has no alpha, so it is dropped there.
Is my color data sent anywhere?
No. Every conversion on this site runs in your browser with no network request, no account and no analytics. You can disconnect and it keeps working.