An RGB to hex converter turns a color's red, green and blue values into the hex code used in CSS and design tools, and turns hex codes back into RGB. Enter either one above to get the other, along with HSL, transparency and each channel in binary. Here's how hex color codes work, how to convert between RGB and hex by hand, and why there are exactly 16,777,216 of them.
How hex color codes work
Screens mix every color from red, green and blue light. Each of the three channels has a value from 0 (off) to 255 (full brightness), which is exactly one byte. A hex color code writes those three bytes in hexadecimal, two digits each, after a #: #RRGGBB. So #FF8000 means red FF (255), green 80 (128) and blue 00 (0), a bright orange. Two hex digits cover 256 values, from 00 to FF, which is why hex is such a compact way to write a byte.
Converting RGB to hex by hand
Convert each channel to two hex digits and write them in order. Divide the value by 16: the whole-number result is the first digit and the remainder is the second, with 10 to 15 written as A to F. For 255, that's 15 remainder 15, or FF. For 128, it's 8 remainder 0, or 80. For 0, it's 00. Put them together and rgb(255, 128, 0) becomes #FF8000. Values below 16 need a leading zero, so 9 is 09, not 9. The decimal to hex converter shows the division for any number.
Converting hex to RGB
To go from hex to RGB, split the code into three pairs and convert each pair to decimal: multiply the first digit by 16 and add the second. In #1E90FF, 1E is 1 × 16 + 14 = 30, 90 is 9 × 16 + 0 = 144, and FF is 255, so the color is rgb(30, 144, 255). The hex to decimal converter walks through each digit if you'd like to check.
Shorthand and transparency
CSS also accepts 3-digit codes, where each digit is doubled: #F80 means #FF8800 and #FFF means white. It only works when both digits of every pair match. For transparency, add a fourth byte, the alpha channel: #RRGGBBAA. FF is fully opaque and 00 fully transparent, so #FF800080 is the same orange at 128/255, about 50% opacity. In RGB notation, the same color is rgba(255, 128, 0, 0.5). The converter accepts all of these forms, and the Opacity field sets the alpha for you.
Colors in binary
Because each channel is one byte, a hex color is a 24-bit number. #FF8000 in binary is 11111111 10000000 00000000: eight bits each for red, green and blue. Read as a single integer, it's 16,744,448. With 256 levels per channel, 256 × 256 × 256 gives 16,777,216 possible colors, which is where the phrase "24-bit true color" comes from. The Channels in binary table shows each byte of your color.
Common colors in hex and RGB
| Color | Hex | RGB |
|---|---|---|
| Black | #000000 | rgb(0, 0, 0) |
| White | #FFFFFF | rgb(255, 255, 255) |
| Red | #FF0000 | rgb(255, 0, 0) |
| Lime | #00FF00 | rgb(0, 255, 0) |
| Blue | #0000FF | rgb(0, 0, 255) |
| Gray | #808080 | rgb(128, 128, 128) |
| Orange | #FFA500 | rgb(255, 165, 0) |
| Dodger blue | #1E90FF | rgb(30, 144, 255) |
Contrast and readable text
When you pick a color for text or a button, check that it stands out from its background. The Web Content Accessibility Guidelines (WCAG) ask for a contrast ratio of at least 4.5:1 for normal text and 3:1 for large text. Contrast depends on how bright each color looks, not on its hex digits: the eye is most sensitive to green, so #00FF00 looks far brighter than #0000FF even though both have one channel at full strength. The preview above switches between dark and light text for the same reason.
RGB, hex and HSL
RGB and hex describe exactly the same thing in two notations. HSL describes the color differently: hue as an angle on the color wheel, then saturation and lightness as percentages. #FF8000 is hsl(30, 100%, 50%), a fully saturated color 30 degrees from red. HSL is handy for making a color lighter or darker by changing a single number, and every modern browser accepts all three forms.
More ways to use it
- Use Pick a color to choose a color visually, then copy its code.
- You can paste
rgb(255, 99, 71)orrgba(…)straight into the hex field to convert it. - For any other hex value, the hex converter shows its decimal, binary and octal forms.
A quick way to read any hex color: the first pair is red, the second green and the third blue. So #FF0000 is pure red, #00FF00 pure green and #808080 a mid gray.