RGB to Hex Converter
Enter red, green, and blue values (0–255) to get the matching hex color code. The conversion happens instantly as you type, and one click copies the hex code for CSS, design tools, or emails.
RGB → Hex
Hex → RGB
Going this direction often? The dedicated hex to RGB converter has its own worked examples and FAQs.
How RGB to Hex Conversion Works
A hex color code is the same three RGB channels written in base 16. Each channel value (0–255) becomes a two-digit hex pair, and the pairs are joined in red, green, blue order behind a #.
To convert a value by hand, divide it by 16: the quotient is the first hex digit and the remainder is the second. Digits above 9 use letters — 10 is A, 11 is B, up to 15 as F. So for 45: 45 ÷ 16 = 2 remainder 13, and 13 is D, giving 2D.
Worked Example: rgb(45, 106, 79)
rgb(45, 106, 79)
├─ 45 ÷ 16 = 2 remainder 13 → 2D (red)
├─ 106 ÷ 16 = 6 remainder 10 → 6A (green)
└─ 79 ÷ 16 = 4 remainder 15 → 4F (blue)
Result: #2D6A4F
Values below 16 divide to a quotient of 0 and keep a leading zero, so rgb(0, 128, 5) becomes #008005.
When You Need Hex vs rgb()
In CSS you rarely have to convert: background: rgb(45 106 79) and background: #2d6a4f render identically. Hex wins where a single compact token matters — design-system tokens, brand guidelines, email HTML, and the color fields in tools like Figma and Photoshop all expect hex. rgb() and rgba() are handy when you're already working with channel numbers or need alpha in older browsers.
Working in HSL instead? Use the HSL to hex and hex to HSL converters, or pick a color visually with the color picker.
Common Colors as RGB and Hex
| Color | RGB | Hex |
|---|---|---|
| Red | rgb(255, 0, 0) | #FF0000 |
| Green | rgb(0, 128, 0) | #008000 |
| Blue | rgb(0, 0, 255) | #0000FF |
| Orange | rgb(255, 165, 0) | #FFA500 |
| White | rgb(255, 255, 255) | #FFFFFF |
| Black | rgb(0, 0, 0) | #000000 |
Shorthand and Alpha
3-digit shorthand: when each hex pair repeats its digit, the code can be halved — #ffaa33 is #fa3. That only works for repeating pairs, so #2d6a4f has no shorthand form.
Alpha: rgba() maps to 8-digit hex. Convert the three channels normally, then multiply the alpha (0–1) by 255 and append it as a fourth pair: rgba(45, 106, 79, 0.5) → 0.5 × 255 ≈ 128 → 80 → #2D6A4F80.
Frequently Asked Questions
-
How do you convert RGB to hex?
Convert each channel value (0–255) to a two-digit base-16 number and join them behind a
#in red, green, blue order. Divide the value by 16: the quotient is the first hex digit and the remainder is the second, with 10–15 written as the letters A–F. For example,rgb(45, 106, 79)becomes#2D6A4F. -
What is the formula for RGB to hex?
For each channel: first digit = value ÷ 16 (whole part), second digit = value mod 16, writing 10–15 as A–F. Applied to 45 that gives 2 and 13 (
D), so 45 becomes2D. Doing the same for 106 (6A) and 79 (4F) and joining the pairs yields#2D6A4F. -
How do I convert rgba() to 8-digit hex?
Convert the red, green, and blue values as usual, then multiply the alpha (0–1) by 255, round it, and append it as a fourth hex pair. For example,
rgba(45, 106, 79, 0.5)has alpha 0.5 × 255 ≈ 128, which is80in hex, so it becomes#2D6A4F80. -
Why do developers prefer hex color codes?
Hex is compact, has no commas or spaces to mistype, and is the default format in design tools, brand guidelines, and email HTML. A single token like
#2D6A4Fis easy to copy, search, and diff, which is why design systems usually store colors as hex. -
Can CSS use RGB and hex interchangeably?
Yes.
background: #2d6a4fandbackground: rgb(45 106 79)render identically — both describe the same sRGB color. Use whichever fits your codebase; conversion only matters when a tool, API, or design spec demands one specific format.
Related tools: hex to RGB · HSL to hex · hex to HSL · color picker · tint & shade generator