RGB to HEX Converter
Convert rgb() and rgba() colors, or plain r, g, b triples, to hex codes. Batch conversion with alpha support.
RGB to HEX Converter: the tool
Input
Hex
The result appears here.How to use RGB to HEX
- Paste one color per line: rgb(30, 144, 255), rgba(255, 0, 0, 0.5), or just 30, 144, 255.
- The hex codes appear as you type. Percentages such as rgb(10% 20% 30%) and the modern space-separated syntax work too.
- Choose Uppercase to get #1E90FF, and Shorten to write #f00 instead of #ff0000 when possible.
- An invalid line is reported with its line number.
Example
Three RGB colors in different notations converted to hex.
rgb(30, 144, 255) 102, 51, 153 rgba(255, 0, 0, 0.5)
#1e90ff #663399 #ff000080
About this tool
Each RGB channel is a number from 0 to 255. A hex color writes each number as two hexadecimal digits and joins them after a #: 255, 0, 0 becomes #ff0000. Values outside the range are clamped to 0 and 255, as CSS does, and decimals are rounded to the nearest whole number.
If the color has an alpha channel, the output is an 8 digit hex code, with the opacity (0 to 1) scaled to a byte. A fully opaque color gets a 6 digit code. The short form is only used when every pair has two equal digits, so the conversion never changes the color.
Frequently asked questions
How do I convert RGB to hex by hand?
Convert each of the three numbers to base 16 and write them as two digits, adding a leading zero if needed. 30 is 1e, 144 is 90 and 255 is ff, which gives #1e90ff.
What about transparency?
rgba(255, 0, 0, 0.5) becomes #ff000080: 0.5 of 255 is 127.5, which rounds to 128, or 80 in hexadecimal. Browsers support 8 digit hex codes in CSS.
Can I use percentages?
Yes. rgb(100% 50% 0%) is read as 255, 128, 0 and converted to #ff8000.
Why does the converter reject hsl() or color names?
This tool is specific to RGB input. The Color converter accepts hex, rgb(), hsl() and CSS color names.
Is the conversion lossless?
For whole-number channels, yes. Converting the hex code back with the HEX to RGB tool gives the original numbers.
More developer tools
- #→HEX to RGB ConverterConvert hex color codes to RGB, one per line. Supports 3, 4, 6 and 8 digit hex, with or without the # sign.
- ◐Color ConverterConvert any CSS color between HEX, RGB, HSL and CMYK, with a color picker and WCAG contrast ratios against white and black.
- cssCSS MinifierRemove comments, whitespace and the last semicolon of every block from CSS. The result behaves exactly like the original.
- cssCSS FormatterBeautify CSS with one declaration per line and consistent indentation. Media queries, nesting, custom properties and data URLs are handled.