RGB to HEX Color Converter
Type RGB values like r55 g25 b166 or rgb(55, 25, 166) to get the HEX code, or paste a HEX code to get RGB. It also reads HSB, HSL, CMYK, OKLCH, LAB and CSS color names. You see every other format right away.
can't be shown exactly on normal sRGB screens.
The values below show the nearest sRGB color. Pick how to find it:
Edit in any color space
Change one value and all the others update.
Results
Enter a color to see its conversions.
Converted
| Input | HEX | RGB | HSL | OKLCH |
|---|
About color conversion
HEX, rgb() and hsl() are three ways to write the same sRGB color, so converting between them is exact. CMYK is different. It depends on the inks, the paper and the press profile, so the value shown here is only a quick estimate. See CMYK and print to learn more. OKLCH, OKLab and CIELAB are perceptual spaces. They can also hold colors that sRGB can't show. If you paste one of those, or a color(display-p3 ...) value, the converter tells you. You can then choose perceptual gamut mapping or plain channel clipping.

How to convert RGB to HEX
An RGB color is three numbers from 0 to 255 for red, green and blue. A HEX code writes the same three numbers in base 16, with two digits each. To convert by hand, divide each number by 16. The whole number is the first digit and the remainder is the second one. The values 10 to 15 are written as the letters A to F.
Take rgb(55, 25, 166), which is also written as r55 g25 b166:
- Red: 55 รท 16 is 3 with 7 left over, so the pair is
37. - Green: 25 รท 16 is 1 with 9 left over, so the pair is
19. - Blue: 166 รท 16 is 10 with 6 left over. 10 is written as A, so the pair is
A6.
Put the three pairs after a # sign and you get #3719A6. To go from HEX back to RGB, work the other way: 37 is 3 ร 16 + 7, which is 55. The HEX guide explains it step by step, and the HEX decoder further down this page does the math for any code you type.
One color, many formats
This is cornflowerblue, one of the CSS color names, written eight ways. Every line below is the same color. Only the way it is written changes.
- HEX
#6495EDThe short code used in CSS, HTML and most design apps. It has two base 16 digits for each channel. - RGB
rgb(100, 149, 237)The same three channels as numbers from 0 to 255. Useful in code that does math with colors. - HSL
hsl(219, 79%, 66%)Hue, saturation and lightness. Easy to change by hand in CSS, for example to make a color a bit lighter. - HSV / HSB
hsv(219, 58%, 93%)What Photoshop and most color pickers show. It is not valid CSS, so convert it before you use it on a website. - CMYK
cmyk(58%, 37%, 0%, 7%)Ink amounts for print. This one is a rough guide. Your printer's color profile gives the real numbers. - OKLCH
oklch(67.46% 0.1414 261.34)Lightness, chroma and hue that follow what the eye sees. Best for even color scales and smooth gradients. - CIELAB
lab(61.23% 3.05 -50.19)An older standard for measuring color in print, paint and fabric. It is used to check how close two colors are. - CSS name
cornflowerblueOne of the 148 named colors in CSS. Only a few colors have a name, so most of them need a code.
Which formats can hold which colors
Each box holds every color in the boxes inside it. A color from an outer box has to be brought inside the sRGB box before it can be written as a HEX code.
- Inside sRGBConverting is exact. HEX, RGB, HSL and HSB are just different ways to write the same numbers.
- Outside sRGBThe converter warns you and finds the closest color that fits. Gamut mapping keeps the hue and lightness. Clipping can shift them.
- CMYK is its own shapePrint inks can't make some bright screen colors, like a vivid blue or green. A CMYK value is a best guess until your printer checks it with their profile.
HEX decoder
Type any HEX code. The decoder splits it into its red, green and blue pairs and shows the base 16 math for each one.
Base 16 digits: 0 to 9 keep their value, then A = 10, B = 11, C = 12, D = 13, E = 14 and F = 15.
Which format should I use?
Pick what you are working on. You get the best format for the job, already filled in with the color from the converter at the top.
How to use the color converter
- Type or paste a color in the box at the top. It can be a HEX code,
rgb(),hsl(), an HSB value such as h204 s85 b76,oklch(),lab()or a CSS color name. - Check the line under the box. It shows how the converter read your input and if the color fits in sRGB.
- Copy the format you need from the Results list. Click a value or the copy button next to it.
- To fine tune the color, change one number under Edit in any color space. All the other formats follow.
- Have a whole list? Switch to Batch convert, paste one color per line, pick a format and copy the table as CSV or JSON.
HSB and HSV values
Photoshop and many other apps show colors as HSB, such as h204 s85 b76. HSB is the same thing as HSV: hue in degrees, then saturation and brightness in percent. Type it into the box above in that form, and the converter gives you the RGB and HEX codes. For example, h204 s85 b76 is #1D80C2. Read more in the guide to HSL and HSV.
Tips for exact results
- HEX codes don't care about upper or lower case.
#6699ffand#6699FFare the same color. - A three digit HEX code is a short form. Each digit is written twice, so
#69Fmeans#6699FF. Only codes where both digits of every pair match can be made short. - An eight digit HEX code adds opacity at the end. In
#6699FF80, the last pair is 128 out of 255, so the color is about half see through. - Going from HEX to HSL and back can change a digit by one. HSL values are rounded to whole numbers, and that is not quite fine enough for every color. Keep the HEX code as your master copy.
- For print, ask your printer which profile they use. The same HEX code can need different CMYK numbers on glossy and plain paper.
Common mistakes
- Mixing up HSL and HSB. Both start with hue, but the last number works differently. Pure red is
hsl(0, 100%, 50%), while in HSB it is 0, 100%, 100%. If you paste HSB numbers intohsl(), you get the wrong color. - Leaving out the # sign. In CSS,
color: 6699FFdoes nothing. It has to be#6699FF. - Typing the letter O instead of zero. HEX digits only go from 0 to 9 and A to F, so an O makes the whole code invalid.
- Expecting screen colors to print the same. Bright screen blues and greens often can't be made with CMYK ink. They come out duller on paper. Check them with a printed proof.
Once you have your code, build a matching palette, check text colors with the contrast checker or browse the color library for named shades.
Color conversion questions
How do I convert RGB to HEX?
Turn each of the three RGB numbers into a two digit base 16 number and write them after a # sign. For example, rgb(255, 99, 71) becomes #FF6347, because 255 is FF, 99 is 63 and 71 is 47.
How do I convert HEX to RGB?
Split the code into three pairs. For each pair, multiply the first digit by 16 and add the second digit. The letters A to F stand for 10 to 15. So #3719A6 is rgb(55, 25, 166).
Is HSB the same as HSL?
No. HSB, also called HSV, and HSL both start with hue, but the other two values work differently. In HSB, 100% brightness is the full color. In HSL, 50% lightness is the full color and 100% is always white. You can't copy the numbers from one to the other.
Why does the CMYK value not match my printer?
Real CMYK numbers depend on the ink, the paper and the press. Printers use a color profile to work them out. This converter uses a simple formula without a profile, so treat its CMYK value as a starting point and ask your printer for a proof.
What does "outside sRGB" mean?
sRGB is the range of colors that normal screens and HEX codes can show. Formats like oklch(), lab() and color(display-p3) can describe brighter colors than that. When you enter one, the converter finds the nearest color that fits, so you still get a HEX code.
Can a HEX code have transparency?
Yes. Add a fourth pair at the end for opacity, such as #6699FF80. 00 is fully clear and FF is fully solid. All modern browsers support 8 digit HEX codes in CSS.