RGB to hex converter
Enter red, green and blue values from 0 to 255 to get the hex color code, such as rgb(255, 128, 0) to #FF8000. Drag the sliders, use the color picker or paste a whole rgb() value, and the hex code updates as you go.
Show the working
Runs in your browser. Nothing you type is uploaded.
How to use the RGB to hex converter
- Type the red, green and blue values, or drag the sliders. The swatch and the hex code change as you go.
- Or pick a color with the picker, or paste a whole value such as
rgb(46, 139, 87)or46 139 87into Paste. - Click any value in the results to copy it. Copy hex copies the main answer, ready for CSS or a design tool.
- Move the Alpha slider below 1 for transparency. The hex code then gets two more digits, such as
#FF800080.
Under the swatch you get the same color as HSL, HSV, CMYK, a single decimal number and binary, plus its contrast against white and black text. To turn a hex code back into red, green and blue, use the Hex to RGB tab above the tool.
How to convert RGB to hex
A hex color code is the three RGB numbers written in base 16, one after another, the same math a decimal to hex converter does on any single number. Each channel from 0 to 255 fits in exactly two hex digits, because 255 is FF. To get the hex code from RGB, take one channel at a time:
- Divide the value by 16. The whole number part is the first hex digit.
- The remainder is the second hex digit.
- Write 10 to 15 as A to F. The hexadecimal table lists every value from 00 to FF if you want to skip the division.
- Join the red, green and blue pairs after a
#.

| Channel | Value | Divide by 16 | Hex |
|---|---|---|---|
| Red | 255 | 15 remainder 15 | FF |
| Green | 128 | 8 remainder 0 | 80 |
| Blue | 0 | 0 remainder 0 | 00 |
Put the three pairs together and rgb(255, 128, 0) becomes #FF8000. Uppercase and lowercase mean the same thing, so #ff8000 is the same color. Open "Show the working" under the tool to see this table for your own values.
RGB to hex code chart
| Color | RGB | Hex code |
|---|---|---|
| Black | 0, 0, 0 | #000000 |
| White | 255, 255, 255 | #FFFFFF |
| Red | 255, 0, 0 | #FF0000 |
| Lime green | 0, 255, 0 | #00FF00 |
| Blue | 0, 0, 255 | #0000FF |
| Yellow | 255, 255, 0 | #FFFF00 |
| Cyan | 0, 255, 255 | #00FFFF |
| Magenta | 255, 0, 255 | #FF00FF |
| Gray | 128, 128, 128 | #808080 |
| Orange | 255, 165, 0 | #FFA500 |

Short hex codes and transparency
When each pair has two matching digits, a hex code can be written in 3 digits: #FF8800 is the same as #F80, and the tool shows the short form when one exists. RGBA colors add a fourth value for opacity, which becomes a fourth hex pair, as MDN's hex color reference shows. FF is fully opaque and 00 is fully transparent, so rgba(255, 128, 0, 0.5) is #FF800080.
RGB, hex, HSL and CMYK
RGB and hex describe the same sRGB color in two notations, so the conversion is exact and works both ways. HSL describes the color by hue, saturation and lightness, which is easier for picking lighter or darker shades. CMYK is for print, and the values shown here are a simple formula, not a printer profile, so use them as a starting point only.
For accessible text, aim for the WCAG minimum contrast of at least 4.5:1 against the background. The tool shows the ratio on white and on black so you can check a brand color before using it for body text.
Frequently asked questions
How do I convert RGB to hex by hand?
Divide each channel by 16. Write the result and the remainder as hex digits (10 to 15 are A to F), then join the three pairs after a #.
What is the hex code for RGB 255, 255, 255?
#FFFFFF, which is white. RGB 0, 0, 0 is #000000, which is black.
Is a hex color code case sensitive?
No. #ff8000 and #FF8000 are the same color in CSS and in design tools.
Can I convert RGBA to hex?
Yes. Set the Alpha slider, or paste an rgba() value, and the tool adds the alpha as the last two hex digits.
How do I get RGB from a hex code?
Use the Hex to RGB tab above the tool, or the hex to RGB converter, and type a code such as #2E8B57. The answer is rgb(46, 139, 87).

