Get the HEX code for an RGB color
Image editors, screen color pickers and brand guidelines often give a color as three numbers: red, green and blue, each between 0 and 255. In a stylesheet, a mockup or a config file, the hexadecimal code is usually preferred because it is shorter and easy to paste from one tool to the next. This page converts while you type, and your values never leave your browser. For the opposite direction, use the HEX to RGB converter.
How to use it
- Enter the three values separated by commas or spaces:
30, 144, 255or30 144 255. You can also paste a wholergb(30, 144, 255), or start from the color picker. For a color taken from a photo, the image color picker reads the pixel directly. - Look at the preview to confirm the shade.
- The HEX code appears on the first line. The Copy button puts it on your clipboard. HSL and CMYK values follow.
The method: divide by 16
Each channel becomes two hexadecimal digits. Divide the value by 16: the quotient is the first digit and the remainder is the second. From 10 to 15, write a, b, c, d, e, f. Here is rgb(30, 144, 255):
- 30 = 1 × 16 + 14, which is
1e - 144 = 9 × 16 + 0, which is
90 - 255 = 15 × 16 + 15, which is
ff
Join the three pairs and you get #1e90ff, a bright blue. The classic mistake when doing this by hand is dropping the leading zero: 0 is written 00 and 10 is written 0a, otherwise the code no longer has six digits. To match other shades to this code, the color palette generator offers complementary, analogous and triadic schemes.
| Color | RGB | HEX |
|---|---|---|
| Tomato | 255, 99, 71 | #ff6347 |
| Teal | 0, 128, 128 | #008080 |
| Goldenrod | 218, 165, 32 | #daa520 |
| Silver | 192, 192, 192 | #c0c0c0 |
| Hot pink | 255, 105, 180 | #ff69b4 |
Frequently asked questions
The code comes out in lower case. Can I write it in capitals?
Yes. #1e90ff and #1E90FF are the same color in CSS and in design software. Which one you use is a matter of convention in your project.
What happens with a value above 255 or a decimal number?
Anything above 255 or below 0 is rejected and an example is shown. A decimal written with a point is rounded to the nearest whole number: 127.5 becomes 128, which is 80.
Can I convert an rgba() color with transparency?
No, the tool expects exactly three values. Remove the fourth one, the alpha, before converting.
When can the code be shortened to three digits?
Only when each pair repeats the same digit: #ff6600 can be written #f60. The tool always shows the full six-digit form.