RGB to HEX Converter
Convert RGB to HEX: enter RGB values or paste an rgb() color to get its hex code.
rgb(30, 144, 255), rgba(30, 144, 255, 0.5) or rgb(30 144 255 / 50%)
- HEX
- #1E90FF
- CSS
- rgb(30, 144, 255)
Need the reverse? Use the HEX to RGB converter. For an opacity slider and Android #AARRGGBB output, try the RGBA to HEX converter.
How to convert RGB to HEX
- Enter red, green and blue values from 0 to 255 — or paste an
rgb()orrgba()value. - Set alpha below 1 if the color should be transparent.
- Copy the 6-digit HEX code, the 8-digit version with alpha, or the short form when there is one.
How the conversion works
Each channel is written as a two-digit hexadecimal number (00–FF) and the three are joined after a #. Numbers below 16 get a leading zero, so 9 becomes 09.
46 → 2 × 16 + 14 → 2E
139 → 8 × 16 + 11 → 8B
87 → 5 × 16 + 7 → 57Alpha is scaled from 0–1 to 0–255 and added as a fourth pair. When every pair has two identical digits, CSS also accepts a short form: #FFCC00 can be written #FC0.
Features
- Number fields with validation: values outside 0–255 are reported, not clamped.
- Paste CSS values in comma or space syntax, including percentages.
- 6-digit, 8-digit (with alpha) and short HEX output with a live preview.
RGB to HEX examples
| Swatch | HEX | RGB / RGBA |
|---|---|---|
| #FFFFFF | rgb(255, 255, 255) | |
| #000000 | rgb(0, 0, 0) | |
| #FF6347 | rgb(255, 99, 71) | |
| #1E90FF | rgb(30, 144, 255) | |
| #2E8B57 | rgb(46, 139, 87) | |
| #FFD700 | rgb(255, 215, 0) | |
| #00000080 | rgba(0, 0, 0, 0.5) | |
| #1E90FF40 | rgba(30, 144, 255, 0.25) |
Common RGB to HEX mistakes
- Dropping the leading zero. Every channel needs two digits: rgb(9, 9, 9) is
#090909, not#999— which is a much lighter gray. - Swapping the channel order. Some APIs, such as Windows GDI and OpenCV, store colors as BGR. Paste those values in the wrong order and red and blue trade places.
- Using the wrong scale. Values from 0 to 1 (as in many shaders and design APIs) must be multiplied by 255 first: 0.5 is 128, or
80in HEX. - Losing transparency. A 6-digit HEX code is always opaque. Keep alpha with an 8-digit code, which the RGBA to HEX converter handles in CSS and Android order.
RGB and HEX values of common colors
| Color | RGB | HEX | CMYK |
|---|---|---|---|
| Gold | 255, 215, 0 | #FFD700 | 0%, 16%, 100%, 0% |
| White | 255, 255, 255 | #FFFFFF | 0%, 0%, 0%, 0% |
| Blue | 0, 0, 255 | #0000FF | 100%, 100%, 0%, 0% |
| Green | 0, 128, 0 | #008000 | 100%, 0%, 100%, 50% |
| Red | 255, 0, 0 | #FF0000 | 0%, 100%, 100%, 0% |
| Orange | 255, 165, 0 | #FFA500 | 0%, 35%, 100%, 0% |
| Black | 0, 0, 0 | #000000 | 0%, 0%, 0%, 100% |
| Yellow | 255, 255, 0 | #FFFF00 | 0%, 0%, 100%, 0% |
| Grey | 128, 128, 128 | #808080 | 0%, 0%, 0%, 50% |
| Pink | 255, 192, 203 | #FFC0CB | 0%, 25%, 20%, 0% |
| Royal Blue | 65, 105, 225 | #4169E1 | 71%, 53%, 0%, 12% |
| Brown | 165, 42, 42 | #A52A2A | 0%, 75%, 75%, 35% |
| Purple | 128, 0, 128 | #800080 | 0%, 100%, 0%, 50% |
| Light Blue | 173, 216, 230 | #ADD8E6 | 25%, 6%, 0%, 10% |
| Cream | 255, 253, 208 | #FFFDD0 | 0%, 1%, 18%, 0% |
| Teal | 0, 128, 128 | #008080 | 100%, 0%, 0%, 50% |
| Dark Blue | 0, 0, 139 | #00008B | 100%, 100%, 0%, 45% |
| Beige | 245, 245, 220 | #F5F5DC | 0%, 0%, 10%, 4% |
| Sky Blue | 135, 206, 235 | #87CEEB | 43%, 12%, 0%, 8% |
| Maroon | 128, 0, 0 | #800000 | 0%, 100%, 100%, 50% |
| Dark Green | 0, 100, 0 | #006400 | 100%, 0%, 100%, 61% |
| Sage Green | 156, 175, 136 | #9CAF88 | 11%, 0%, 22%, 31% |
| Khaki | 240, 230, 140 | #F0E68C | 0%, 4%, 42%, 6% |
| Burgundy | 128, 0, 32 | #800020 | 0%, 100%, 75%, 50% |
| Navy Blue | 0, 0, 128 | #000080 | 100%, 100%, 0%, 50% |
| Emerald Green | 80, 200, 120 | #50C878 | 60%, 0%, 40%, 22% |
| Light Grey | 211, 211, 211 | #D3D3D3 | 0%, 0%, 0%, 17% |
| Magenta | 255, 0, 255 | #FF00FF | 0%, 100%, 0%, 0% |
| Silver | 192, 192, 192 | #C0C0C0 | 0%, 0%, 0%, 25% |
| Lavender | 230, 230, 250 | #E6E6FA | 8%, 8%, 0%, 2% |
| Lime | 0, 255, 0 | #00FF00 | 100%, 0%, 100%, 0% |
| Cyan | 0, 255, 255 | #00FFFF | 100%, 0%, 0%, 0% |
| Coral | 255, 127, 80 | #FF7F50 | 0%, 50%, 69%, 0% |
| Tomato | 255, 99, 71 | #FF6347 | 0%, 61%, 72%, 0% |
| Crimson | 220, 20, 60 | #DC143C | 0%, 91%, 73%, 14% |
| Hot Pink | 255, 105, 180 | #FF69B4 | 0%, 59%, 29%, 0% |
| Turquoise | 64, 224, 208 | #40E0D0 | 71%, 0%, 7%, 12% |
| Dodger Blue | 30, 144, 255 | #1E90FF | 88%, 44%, 0%, 0% |
| Indigo | 75, 0, 130 | #4B0082 | 42%, 100%, 0%, 49% |
| Olive | 128, 128, 0 | #808000 | 0%, 0%, 100%, 50% |
Related color tools
The other color converters: HEX to RGB, RGBA to HEX, RGB to CMYK and CMYK to RGB. To find a color visually, use the color picker; for every CSS color name, see the HTML color codes.
Frequently asked questions
- How do I convert RGB to HEX by hand?
- Convert each channel (0–255) to a two-digit base-16 number and join them. rgb(30, 144, 255) becomes 1E, 90 and FF, so the HEX code is #1E90FF.
- How is alpha converted?
- Alpha from 0 to 1 is multiplied by 255 and written as two more hex digits. An alpha of 0.5 becomes 80, so rgba(30, 144, 255, 0.5) is #1E90FF80.
- Why does the converter reject 256 or negative values?
- Each RGB channel is one byte, so it must be between 0 and 255. Instead of silently clamping a typo to a different color, the converter tells you which value is out of range.
- Can I use decimals?
- Yes. CSS allows fractional RGB values, so the converter accepts them and rounds to the nearest whole number for the HEX code.
- Can I set alpha as a percentage?
- Paste a value such as rgb(30 144 255 / 50%) and the percentage is converted to the alpha pair (80). For an opacity slider and the Android #AARRGGBB order, use the RGBA to HEX converter.
- What are the HEX codes for black, white and pure red?
- Black rgb(0, 0, 0) is #000000, white rgb(255, 255, 255) is #FFFFFF and pure red rgb(255, 0, 0) is #FF0000. The reference table on this page lists about 40 more common colors with their RGB, HEX and CMYK values.
- Why are red and blue swapped after converting?
- The values probably came from a source that stores colors as BGR, such as Windows GDI or OpenCV. Enter them in R, G, B order — or swap the first and last numbers — before converting.
- Should I use HEX or rgb() in CSS?
- Either: browsers treat #1E90FF and rgb(30 144 255) as exactly the same color. HEX is shorter and common in design handoffs; rgb() is easier to read and to give an alpha value, as in rgb(30 144 255 / 50%).
Related tools
- HEX to RGB converterConvert HEX color codes to RGB and RGBA.
- Color pickerPick colors and copy HEX, RGB, HSL and CMYK values.
- RGB to CMYK converterConvert RGB values to approximate CMYK percentages.
- HTML color codesSearch the CSS color names and copy HEX or RGB codes.
- RGBA to HEX converterConvert RGBA to 8-digit HEX (CSS and Android order).