RGB to Hex Converter
Type three numbers from 0 to 255 for red, green and blue. You get the hex code and a preview of the color.
How it works
Screens make every color by mixing red, green and blue light. Each of the three is set to a level from 0, which is off, to 255, which is full strength. That gives 256 × 256 × 256, or about 16.7 million, possible colors.
RGB writes the three levels as ordinary numbers: rgb(91, 61, 245). Hex writes the same three levels in base 16, two digits each, after a hash sign: #5B3DF5. The two forms describe exactly the same color.
To convert RGB to hex, take each number in turn. Divide it by 16. The whole number part is the first hex digit and the remainder is the second. Write 10 to 15 as the letters A to F.
- 91 ÷ 16 is 5 remainder 11, so
5B - 61 ÷ 16 is 3 remainder 13, so
3D - 245 ÷ 16 is 15 remainder 5, so
F5
Join the three pairs and add a hash sign: #5B3DF5.
What you can type. The box accepts 91, 61, 245, 91 61 245 or the CSS form rgb(91, 61, 245). Each value must be a whole number from 0 to 255.
Why both forms exist. Hex is compact, which is why it became the habit in web design and in design tools. RGB is easier to read and to change by hand, and it is what most programming languages and image editors show.
Worked example
rgb(0, 128, 255): 0 is 00. 128 ÷ 16 is 8 remainder 0, so 80. 255 ÷ 16 is 15 remainder 15, so FF. The hex code is #0080FF.
Common questions
How do I convert RGB to hex by hand?
Divide each value by 16. The whole part is the first digit and the remainder is the second, with 10 to 15 written as A to F. Join the three pairs.
What is rgb(255, 0, 0) in hex?
#FF0000, pure red.
Can RGB values go above 255?
No. Each channel is stored in one byte, which holds 0 to 255.