RGB to HEX Converter

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

Updated

Color Tools● Free No upload Instant

Loading RGB to HEX Converter…

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

Quick answer

Enter red, green and blue as numbers from 0 to 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, and this packs them into the hex that stylesheets 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 (a single digit gets 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 and 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, which is every code this tool can produce.

Accuracy and limits

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. The rounding and clamping are deliberate: you always get a valid code, but a messy input won't round-trip perfectly.

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 uses

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 it fits, and when it doesn't

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

  • Going the other way, from hex to 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. Commas, spaces or a full rgb(…) wrapper all work, because the tool 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?
It's a convention: design tools commonly show uppercase hex, and it 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 numbers from 0 to 255, 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, making 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. rgb() works just as well, 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

Checked against the converter's code: it clamps channels to 0-255 and rounds decimals before encoding, so the output is always a valid six-digit hex and exact for whole-number RGB.

Popular

HEX to RGB Converter

Turn a hex color into its red, green and blue numbers and the CSS rgb() string, exactly.

ColorOpen Tool
PopularHot

Color Picker

Pick a colour with the swatch or type a hex code, and read it back as HEX, RGB, HSL and CMYK side by side. Your browser does every conversion.

ColorOpen Tool
Editor's Pick

Contrast Checker

Check whether your text and background colours have enough contrast to read, with a pass or fail at each WCAG accessibility level.

ColorOpen Tool
PopularHot

Image Compressor

Compress an image to JPEG with a quality slider and watch the file size drop as you drag, in your browser.

ImageOpen Tool
PopularHot

Merge PDF

Combine several PDFs into one file in the order you choose, without leaving your browser.

PDFOpen Tool
PopularHot

Word Counter

Count words, characters, sentences and paragraphs as you type, with reading and speaking time alongside.

TextOpen Tool

Back to the RGB to HEX Converter

Paste or pick your input at the top of the page. The conversion runs on this device and needs no account.