RGB to HEX Converter
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%)
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) |
Related color tools
Convert back with HEX to RGB, prepare colors for print with RGB to CMYK, or explore colors visually in the color picker.
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.