RGB to HEX Converter
Enter red, green and blue values — as rgb(255, 165, 0) or just 255, 165, 0 — to get the matching hex color code.
HEX
#ffa500
RGB
rgb(255, 165, 0)
HSL
hsl(39, 100%, 50%)
HSV / HSB
hsv(39, 100%, 100%)
CMYK
cmyk(0%, 35%, 100%, 0%)
RGB 0–1
1.000, 0.647, 0.000
Text contrast (WCAG)
On white — Aa1.97:1 · Fail
On black — Aa10.63:1 · AAA
Advertisement
The RGB to HEX formula
Each RGB channel is a number from 0 to 255. To turn it into two hex digits, divide by 16: the whole part is the first digit and the remainder is the second (10–15 are written A–F). Then join red, green and blue and put a # in front.
Worked example for rgb(255, 165, 0): 255 ÷ 16 = 15 remainder 15 → FF; 165 ÷ 16 = 10 remainder 5 → A5; 0 → 00. Result: #FFA500. Single-digit results always get a leading zero, so 9 becomes 09, not 9.
RGB to HEX in code
JavaScript:
const toHex = (r, g, b) =>
"#" + [r, g, b].map(n => n.toString(16).padStart(2, "0")).join("");
toHex(255, 165, 0); // "#ffa500"Python:
"#{:02x}{:02x}{:02x}".format(255, 165, 0)
# '#ffa500'Common RGB values and their hex codes
| Color | RGB | HEX |
|---|---|---|
| Black | rgb(0, 0, 0) | #000000 |
| White | rgb(255, 255, 255) | #ffffff |
| Red | rgb(255, 0, 0) | #ff0000 |
| Green | rgb(0, 128, 0) | #008000 |
| Lime | rgb(0, 255, 0) | #00ff00 |
| Blue | rgb(0, 0, 255) | #0000ff |
| Yellow | rgb(255, 255, 0) | #ffff00 |
| Orange | rgb(255, 165, 0) | #ffa500 |
| Purple | rgb(128, 0, 128) | #800080 |
| Navy | rgb(0, 0, 128) | #000080 |
| Teal | rgb(0, 128, 128) | #008080 |
| Gray | rgb(128, 128, 128) | #808080 |
| Silver | rgb(192, 192, 192) | #c0c0c0 |
| Maroon | rgb(128, 0, 0) | #800000 |
| Pink | rgb(255, 192, 203) | #ffc0cb |
| Gold | rgb(255, 215, 0) | #ffd700 |
Frequently asked questions
- What input formats work?
- rgb(255, 165, 0), rgba(255, 165, 0, 0.5), the modern rgb(255 165 0) syntax, or just three numbers separated by commas or spaces.
- What if a value is above 255?
- RGB channels only go from 0 to 255, so the tool shows an error instead of guessing.
- Should hex codes be upper or lower case?
- Either. #FFA500 and #ffa500 are the same color; CSS, HTML and design tools treat them identically.