RGB to HEX Converter

Turn RGB and RGBA values into HEX color codes with sliders, alpha support and automatic shorthand detection.

Runs in your browser

RGB color

Also accepts 255 99 71, rgba() and HEX

Preview

HEX result

HEX
#ff6347
CSS
color: #ff6347;
RGBA
rgba(255, 99, 71, 1)
No 3-digit shorthand exists for #ff6347: shorthand only works when both digits of every pair are the same, like #ff6600 → #f60.

How it was calculated

  1. Red: 255 ÷ 16 = 15 remainder 15 → f and f = ff
  2. Green: 99 ÷ 16 = 6 remainder 3 → 6 and 3 = 63
  3. Blue: 71 ÷ 16 = 4 remainder 7 → 4 and 7 = 47

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

  1. 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) or 34, 197, 94.
  2. Tick Include alpha (it switches on automatically when you paste an rgba value) to get an 8-digit HEX code.
  3. Choose uppercase if your style guide prefers #FF6347 over #ff6347.
  4. 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.