How to convert RGB to HEX
- Take each RGB value from 0 to 255.
- Divide it by 16: the whole part is the first hex digit and the remainder the second (102 = 6 × 16 + 6 → 66).
- Use the digits 0–9 and a–f (a = 10 … f = 15), so 255 is ff and 0 is 00.
- Join the three pairs after a #: rgb(255, 102, 0) is #ff6600. For alpha, multiply by 255, round, and add a fourth pair.
Why convert RGB to HEX
Many programs and color pickers show colors as RGB numbers, while style guides, CSS files and brand documents usually list HEX codes. Converting gives you a short code that is easy to share, paste into a website builder or keep in a palette. The conversion is exact, so nothing about the color changes.
When the color has transparency, the alpha value from 0 to 1 becomes a fourth pair of hex digits. rgba(255, 102, 0, 0.5) becomes #ff660080. Some older software does not understand 8-digit HEX codes; in that case use the 6-digit code with a separate opacity setting.
Checking your values
Each RGB value must be a whole number between 0 and 255. Values from image editors are sometimes given as percentages, such as rgb(100%, 40%, 0%); this converter accepts those too and turns them into 0–255 values first.
If you have three numbers without the rgb() wrapper, such as 255, 102, 0, you can paste them directly. The converter reads them as red, green and blue. The modern CSS syntax rgb(255 102 0 / 50%) with spaces and a slash works as well.
Common RGB to HEX pairs
A few values are worth knowing by heart: 0 is 00, 128 is 80, 192 is c0 and 255 is ff. So rgb(128, 128, 128) is #808080, a middle grey, and rgb(192, 192, 192) is #c0c0c0, the CSS color silver. When all three pairs repeat a digit, as in #ff6600, you can shorten the code to #f60.
If you work with many colors, keep the HEX codes in one list and convert from there, so every tool uses the same exact values.
RGB to HEX chart of common colors
RGB to HEX values for common colors| Color | RGB | HEX |
|---|
| Black | rgb(0, 0, 0) | #000000 |
| White | rgb(255, 255, 255) | #ffffff |
| 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 |
| Tomato | rgb(255, 99, 71) | #ff6347 |
Other colors: use the converter above or the Color Converter.