Converting RGB to a HEX color code
RGB describes a color with three numbers from 0 to 255 — how much red, green and blue light to mix. HEX writes exactly the same three numbers in base 16 and glues them together after a #. Converting is lossless: rgb(255, 99, 71) and #ff6347 (the named color tomato) are the same color, just in different notation.
Each channel becomes two hex digits. Divide the number by 16: the whole-number result is the first digit and the remainder is the second, with 10–15 written as a–f. For 99 that gives 6 remainder 3, so 63. Values below 16 need a leading zero — 7 becomes 07, not 7 — which is the most common mistake when converting by hand.
Transparency works too. An alpha value between 0 and 1 is multiplied by 255 and rounded, then appended as a fourth pair to make an 8-digit HEX code. This tool also tells you when a color has a 3 or 4-digit shorthand, which is handy for short, readable stylesheets.
How to use the RGB to HEX Converter
- Drag the Red, Green and Blue sliders, type exact numbers in the boxes, or paste a value such as
rgb(255 99 71),rgba(0, 0, 0, 0.6)or34, 197, 94. - Tick Include alpha (it switches on automatically when you paste an rgba value) to get an 8-digit HEX code.
- Choose uppercase if your style guide prefers
#FF6347over#ff6347. - Copy the HEX, shorthand or ready-made CSS declaration, and check the step-by-step math if you want to verify the result.
Example
A translucent black overlay, common for modals and image captions:
rgba(0, 0, 0, 0.6)
Red 0 → 00
Green 0 → 00
Blue 0 → 00
Alpha 0.6 × 255 = 153 → 99
= #00000099 (shorthand #0009)Common alpha values in HEX
- 100% →
ff - 90% →
e6 - 80% →
cc - 75% →
bf - 60% →
99 - 50% →
80 - 25% →
40 - 10% →
1a - 0% →
00
Frequently Asked Questions
When can a HEX code be shortened to 3 digits?
Only when both digits in every pair are identical. #ff6600 → #f60 and #aabbcc → #abc work, but #ff6347 cannot be shortened. The same rule applies to 8-digit codes and their 4-digit form, like #00000099 → #0009.
Are uppercase and lowercase HEX codes different?
No. HEX digits are case-insensitive in CSS, HTML and SVG. Lowercase is slightly more common and compresses marginally better with gzip; pick one and stay consistent.
What happens to values above 255?
RGB channels are limited to 0–255 in HEX. CSS clamps larger numbers in rgb(), but they usually point to a typo, so this tool rejects them in the paste box and the sliders stop at the valid range.
Is 8-digit HEX supported everywhere?
All current browsers support #rrggbbaa and #rgba. Some older tools, email clients and design apps only read 6 digits — use rgba() there, or get every format at once from the Color Converter. For the reverse direction, see HEX to RGB.