RGB to HEX
Convert any RGB color to its HEX code instantly. Drag the sliders, type the numbers or paste a value like rgb(12, 34, 56), and copy the HEX, HSL or ready-made CSS with one click.
Also accepts rgba(), percentages and HEX codes.
#1E90FF–Common colors Click a color to load it
How to use the RGB to HEX
- Enter your RGB values with the sliders or the number boxes (0 to 255 each).
- Or paste a value such as rgb(12, 34, 56), 12,34,56 or 12 34 56 and press Convert.
- Read the HEX code on the swatch and in the results. Tick Lowercase HEX if you prefer #1e90ff.
- Add transparency with Include alpha to get an 8-digit HEX like #1E90FF80.
- Press Copy next to HEX, RGB, HSL or the CSS variable to use it in your code or design app.
RGB to HEX formula
HEX is the same RGB color written in base 16. Each channel from 0 to 255 becomes two hex digits from 00 to FF: divide the value by 16, the whole number is the first digit and the remainder is the second. The digits 10 to 15 are written A to F.
Worked example: rgb(12, 34, 56). 12 ÷ 16 = 0 remainder 12, so 0C. 34 ÷ 16 = 2 remainder 2, so 22. 56 ÷ 16 = 3 remainder 8, so 38. Together that gives #0C2238.
| Decimal | 0 | 17 | 51 | 102 | 128 | 153 | 204 | 255 |
|---|---|---|---|---|---|---|---|---|
| HEX | 00 | 11 | 33 | 66 | 80 | 99 | CC | FF |
Alpha values in 8-digit HEX
With transparency, a fourth pair is added at the end: alpha × 255, rounded and written in hex. Here are common opacity levels.
| Opacity | 100% | 90% | 75% | 50% | 25% | 10% | 0% |
|---|---|---|---|---|---|---|---|
| HEX suffix | FF | E6 | BF | 80 | 40 | 1A | 00 |
Picking readable text colors
The swatch shows the contrast ratio of your color against white and black text, using the WCAG formula. A ratio of at least 4.5:1 is recommended for normal body text and 3:1 for large headings. The swatch automatically uses whichever text color reads better. To go the other way, from a HEX code to RGB values, use HEX to RGB, and for print colors try RGB to CMYK.
Frequently asked questions
How do I convert RGB to HEX?
Convert each of the red, green and blue values (0 to 255) to a two-digit hexadecimal number and join them after a # sign. For rgb(30, 144, 255): 30 is 1E, 144 is 90 and 255 is FF, so the HEX code is #1E90FF.
What is the HEX code for rgb(255, 255, 255)?
rgb(255, 255, 255) is pure white, which is #FFFFFF in HEX, or #FFF in short form. rgb(0, 0, 0) is black, #000000 or #000.
When can a HEX color be written with 3 digits?
A short HEX like #F80 works only when both digits of each pair are the same, as in #FF8800. That happens when each RGB value is a multiple of 17, such as 0, 17, 34, 51 and so on up to 255. The tool shows the short form whenever it is possible.
How do I convert RGBA to HEX with transparency?
Tick Include alpha and set the opacity. The alpha value is multiplied by 255 and added as a fourth pair, so 50% opacity becomes 80 and rgba(30, 144, 255, 0.5) becomes #1E90FF80. Modern browsers support 8-digit HEX in CSS.
Are HEX color codes case sensitive?
No. #1E90FF and #1e90ff are the same color in CSS, HTML and design tools. Use whichever style your project prefers. The Lowercase HEX option switches the output.
Is RGB or HEX better for CSS?
They describe exactly the same colors, so the choice is a matter of style. HEX is short and common in design handoffs, while rgb() and hsl() are easier to read and adjust, and make transparency obvious.