RGB to HEX Converter

Pack red, green and blue numbers into the compact #RRGGBB hex code the web runs on.

Color Tools Free No upload Instant

Loading RGB to HEX Converter…

Your browser is preparing the tool. It runs 100% locally.

Quick Answer

Enter three numbers — red, green and blue, each 0–255 — and this returns the hex color code, like 139, 92, 246 → #8B5CF6. Each channel becomes a two-digit, zero-padded base-16 pair, joined behind a #. Decimal or out-of-range values are rounded and clamped to 0–255 first, so you always get a valid six-digit hex.

What the RGB to HEX Converter Does

Type red, green and blue values and the tool returns the matching hex code in uppercase, with a live swatch. It reads the numbers out of whatever you paste, so '139, 92, 246', '139 92 246' and even a full rgb(139 92 246) all work. It opens on 139, 92, 246 so there's a result on screen straight away.

Hex is the web's compact color token: one short string you can drop into CSS or HTML, copy into a design tool, or paste into a chat. Photoshop, Figma, OS color pickers and screenshot eyedroppers tend to hand you RGB numbers — this packs them into the hex that stylesheets actually use.

How It Works

The tool pulls the numeric groups out of your input, so the separators you use don't matter. It then clamps each channel to the 0–255 range, rounds it to a whole number, and writes it as a two-digit hexadecimal pair — padding a single digit with a leading zero — before joining the three pairs behind a #.

The output is uppercase by convention, though #8B5CF6 and #8b5cf6 are the same color. It updates as you type, and the result is reversible: run it through HEX to RGB and you get your numbers back (as long as they were whole values inside 0–255 to begin with).

Data source & conversion logic

No data is fetched. Hex is simply RGB re-encoded in base 16, so the conversion is pure arithmetic: each 0–255 channel maps to exactly one two-digit pair from 00 to FF, as defined for sRGB and CSS hex colors.

  1. Step 1. Read the numbers from your input — the tool grabs the digit groups, so commas, spaces or an rgb() wrapper all work.
  2. Step 2. Clamp each channel into the 0–255 range and round it to a whole number.
  3. Step 3. Convert each channel to a two-digit hex pair, padding a single digit with a leading zero (9 becomes 09).
  4. Step 4. Join the three pairs behind a #, in red-green-blue order.
  5. Step 5. Show the uppercase hex code and preview the swatch.

RGB to Hex

R, G, B → #[hex2(R)][hex2(G)][hex2(B)] (each channel 0–255 becomes a 2-digit pair 00–FF)
Worked examples
139, 92, 246 → 8B, 5C, F6 → #8B5CF6
255, 102, 0 → FF, 66, 00 → #FF6600

Single-digit hex results are zero-padded — 0 becomes 00, 9 becomes 09 — so every code is exactly six digits. Values above 255 or below 0 are clamped before encoding.

Technical Details

InputR, G, B (0–255 each); separators flexible
Output#RRGGBB, uppercase
ClampingValues outside 0–255 are clamped
RoundingDecimals rounded to the nearest integer
PaddingSingle-digit channels zero-padded
AlphaNot added — six-digit hex only
ReversibleYes, with HEX to RGB (whole-number input)
Where it runsIn your browser, live

Standards & references

  • sRGB 8-bit channels — each channel is an 8-bit value from 0 to 255, the range a two-digit hex pair (00–FF) can hold.
  • CSS hex notation — the #RRGGBB output is the standard CSS and HTML hex form, accepted everywhere a color is expected.
  • 24-bit truecolor — three 8-bit channels combine for 16,777,216 colors — every code this tool can produce.

Accuracy & Limitations

For whole numbers in 0–255 the conversion is exact and reversible: send the hex through HEX to RGB and the original channels come back.

Decimals are rounded and out-of-range numbers clamped, so rgb(300, -5, 128.7) becomes #FF0081. That guarantees a valid code, but it also means a messy input won't round-trip perfectly — the rounding and clamping are deliberate.

It reads numbers only. Percentage notation like rgb(50%, …) isn't supported; convert a percentage to its 0–255 value first (50% is about 128).

The result is a six-digit hex with no alpha. For transparency, append a fourth pair by hand to make an eight-digit #RRGGBBAA color.

Real-World Use Cases

Photoshop and Figma readouts

Turn the RGB numbers a design app reports into the hex code your CSS or HTML needs.

Eyedropper and screenshot samples

Convert an RGB value sampled from an image or the screen into a single shareable hex token.

Normalising values from code

Take RGB produced by a script or spreadsheet and standardise it as web-ready hex.

Tidying rgb() into hex

Shorten a verbose rgb() declaration into the compact hex form for cleaner stylesheets.

When to use it — and when not to

Good for

  • Packing RGB numbers into a CSS or HTML hex
  • Sharing a color as one compact token
  • Converting picker, Photoshop or Figma output
  • Standardising numeric colors as web hex

Not the best choice for

  • The reverse — reading a hex as numbers
  • Percentage RGB inputs
  • Colors that need transparency

Already have a hex and want the numbers? Use HEX to RGB. Need to fine-tune the color? Convert to HSL. For transparency, append an alpha pair to make an eight-digit hex yourself.

Frequently Asked Questions

How do I convert RGB to a hex code?
Write each channel as a two-digit base-16 number and join them: red, then green, then blue, behind a #. So 139, 92, 246 becomes 8B, 5C, F6, which is #8B5CF6. The tool handles the arithmetic and the zero-padding.
How should I type the RGB values in?
As three numbers in red-green-blue order. The separators don't matter — commas, spaces, or even a full rgb(…) wrapper all work, because the tool just reads the numeric groups it finds.
What happens if a value is above 255 or negative?
It's clamped into the 0–255 range before encoding: anything over 255 becomes 255 (FF) and anything below 0 becomes 0 (00). That keeps the output a valid hex even if the input was out of range.
What about decimal values like 128.7?
They're rounded to the nearest whole number first, since a hex channel has to be an integer. 128.7 rounds to 129, which is 81 in hex.
Why is the hex shown in uppercase?
Convention — uppercase hex is common in design tools and is a little easier to read. It makes no difference to the color: #8B5CF6 and #8b5cf6 are identical.
Can I paste a whole rgb(...) string?
Yes. The tool extracts the numbers from whatever you paste, so rgb(139, 92, 246) converts just as well as typing the three values plainly.
Does it support percentage RGB?
No — it expects 0–255 numbers, not percentages. Convert a percentage to its 0–255 equivalent first; for example 50% is roughly 128, and 100% is 255.
How do I add transparency to the result?
Hex transparency uses an extra pair on the end — an eight-digit #RRGGBBAA code. This tool outputs the six-digit color; append your own alpha pair (00 is fully transparent, FF fully opaque) to add it.
Is the conversion reversible?
Yes, for whole numbers in range. Feed the hex into HEX to RGB and you recover the original channels. Only rounded or clamped inputs won't come back exactly, because the rounding already changed them.
Why use hex in CSS instead of rgb()?
Mostly brevity and habit: a hex code is one compact token that's quick to copy, paste and scan in a stylesheet. Functionally rgb() is equally valid — and it's the better choice when you want to add an alpha channel.
Is anything uploaded when I convert?
No. The conversion runs entirely in your browser, so the values you enter never leave your device.
What color space does this assume?
sRGB, the web's standard space. The numbers you enter are treated as sRGB channels, and the hex describes that same sRGB color.

References

Out-of-range or decimal channels are clamped to 0–255 and rounded before encoding, so the output is always a valid six-digit hex — and exact for whole-number RGB.

PopularHot

Color Picker

Use Color Picker to choose and convert color precisely — instant and free.

ColorOpen Tool
Popular

HEX to RGB Converter

Use HEX to RGB Converter to choose and convert color precisely — instant and free.

ColorOpen Tool
Trending

Color Palette Generator

Use Color Palette Generator to choose and convert color precisely — instant and free.

ColorOpen Tool
Trending

Gradient Generator

Use Gradient Generator to choose and convert color precisely — instant and free.

ColorOpen Tool
Editor's Pick

Contrast Checker

Use Contrast Checker to choose and convert color precisely — instant and free.

ColorOpen Tool

HEX to HSL Converter

HEX to HSL Converter online — accurate color values, palettes and previews in-browser.

ColorOpen Tool

Ready to try the RGB to HEX Converter?

It is free, private and runs entirely in your browser — no sign-up, no uploads, no limits.