HEX to RGB Converter

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

Updated

Color ToolsPopular● Free No upload Instant

Loading HEX to RGB Converter…

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

Quick answer

Paste a hex color such as #8B5CF6 and this returns its red, green and blue values, 139, 92, 246, plus the CSS string rgb(139, 92, 246). Each hex pair is one 0-255 channel written in base 16, so the conversion is exact. Three-digit shorthand like #F90 is expanded before converting.

What the HEX to RGB Converter does

Type a hex color and the tool shows its three RGB channels as decimal numbers from 0 to 255, plus the CSS rgb() string you can paste into a stylesheet. It accepts the six-digit form and the three-digit shorthand, with or without the #, and it repaints a swatch and recalculates on every keystroke. It opens on #8B5CF6 as a worked example.

You need decimal RGB when a hex token won't work: a canvas or WebGL call, an image library in Python or JavaScript, a spreadsheet that builds colors from numbers, a game engine, or an rgba() value where you want the channels separate from the opacity.

How it works

A hex color is RGB written in base 16. The six digits are three pairs, one each for red, green and blue. The tool strips the #, expands any three-digit shorthand to six digits, then reads each pair as a number from 0 (written 00) to 255 (written FF).

That mapping is exact, so no color science or rounding is involved: #8B5CF6 always comes back as 139, 92, 246. The page recomputes on every keystroke, and feeding the result into the RGB-to-HEX tool returns the original hex.

Data source & conversion logic

The tool fetches no color data. Hex notation encodes an sRGB color as three two-digit pairs, each one 8-bit channel in base 16, so the conversion is plain arithmetic done in the page.

  1. Step 1. Remove the leading # if it's there.
  2. Step 2. If the value is a three-digit shorthand, expand each digit to a pair (F to FF, 9 to 99).
  3. Step 3. Split the six digits into three pairs: red, green, blue.
  4. Step 4. Read each pair as a base-16 number, giving a 0-255 value per channel.
  5. Step 5. Show the three numbers, assemble the CSS rgb() string, and preview the swatch.

Hex to RGB

#RRGGBB → R = base16(RR), G = base16(GG), B = base16(BB) (each pair runs 00-FF, which is 0-255 in decimal)
Worked examples
#8B5CF6 → 8B = 139, 5C = 92, F6 = 246 → rgb(139, 92, 246)
#F90 → expands to #FF9900 → rgb(255, 153, 0)

FF is the largest two-digit hex value (255 in decimal) and 00 the smallest (0). Each channel spans the full 0-255 range, which is why the conversion is exact and reversible.

Technical details

InputHex #RRGGBB or #RGB shorthand
OutputR, G, B (0-255) plus CSS rgb()
ConversionExact, base-16 to decimal
Channels8-bit, 0-255 each
ShorthandThree-digit hex expanded automatically
HashOptional; works with or without it
AlphaEight-digit #RRGGBBAA not parsed
Where it runsIn your browser, live

Standards and references

  • sRGB hex notation: every two-digit pair in #RRGGBB is one 8-bit channel (00-FF maps to 0-255), as defined for sRGB and CSS hex colors.
  • CSS Color: rgb(): the rgb() string the tool outputs is the standard CSS functional notation, valid in any stylesheet.
  • 24-bit truecolor: three 8-bit channels give 16,777,216 possible colors, the range a six-digit hex can describe.

Accuracy and limits

Hex and RGB are two notations for the same 8-bit sRGB value, so the conversion is exact and reversible with no rounding drift. Run the output back through RGB to HEX and you get the original hex.

It expects a three- or six-digit hex. An eight-digit hex carrying alpha (#RRGGBBAA) or a named color won't parse and shows an 'invalid input' notice. Strip the alpha pair first, or read it separately as opacity.

Values are read as sRGB. A hex copied out of a wide-gamut (Display P3) workflow is converted as plain sRGB numbers, not remapped to that gamut.

Real-world uses

Canvas, WebGL and game engines

Get the raw 0-255 channels these APIs expect, instead of passing a hex string they can't read.

Building rgba() with opacity

Take the three RGB numbers and add your own alpha to make a semi-transparent rgba() color.

Image scripts and libraries

Feed integer RGB into Python, JavaScript or other image-processing code that works in numbers, not hex.

Spreadsheets and data viz

Drive conditional formatting or chart colors that are defined by numeric channels rather than a hex token.

When it fits, and when it doesn't

Good for

  • Turning a CSS or design hex into numeric RGB
  • Feeding 0-255 channels to canvas, scripts or engines
  • Building an rgba() color with custom opacity
  • Checking what a hex equals in plain numbers

Not the best choice for

  • Going the other way, from numbers to hex
  • Adjusting hue, saturation or lightness
  • Parsing an eight-digit hex with an alpha pair

For the reverse, use RGB to HEX. To adjust a color by hue or lightness, convert it to HSL. For an alpha hex, drop the last pair here and treat it as opacity separately.

Frequently asked questions

How do I read a hex color as RGB?
Split the six digits into three pairs (red, green, blue) and read each pair as a base-16 number from 00 (0) to FF (255). The tool does this for you and also writes out the CSS rgb() string.
Does it accept three-digit shorthand like #F90?
Yes. Each shorthand digit is doubled to make a full pair, so #F90 becomes #FF9900 and converts to rgb(255, 153, 0). The result is identical to typing the long form.
Do I need to include the # symbol?
No. The tool strips a leading # if it's present and works fine without one, so 8B5CF6 and #8B5CF6 give the same result.
What about an eight-digit hex with alpha (#RRGGBBAA)?
No. The tool handles three- and six-digit hex only and flags an eight-digit value as invalid. Remove the final alpha pair to convert the color, and treat that pair separately as opacity if you need it.
Is the conversion exact, or is there rounding?
It's exact. Hex and RGB are the same 8-bit value in two notations, so nothing is approximated. Convert the result back with RGB to HEX and you'll recover the original code.
What's the difference between the three numbers and the rgb() string?
They hold the same data. The three numbers are the bare channels (139, 92, 246); the rgb() string wraps them in CSS functional notation, rgb(139, 92, 246), ready to paste into a stylesheet.
Why convert hex to RGB at all?
Plenty of contexts can't take a hex string: a canvas or WebGL call, an image library, a spreadsheet, a game engine, or an rgba() value where you want the channels separate from the alpha. Those all want decimal RGB.
What's the maximum value for a channel?
255, written FF in hex. The minimum is 0, written 00. Each of the three channels covers that full 0-255 range, which gives 24-bit color its 16.7 million combinations.
Does the letter case of the hex matter?
No. Hex is case-insensitive, so #8b5cf6 and #8B5CF6 convert to exactly the same RGB values.
Does #FFFFFF really equal rgb(255, 255, 255)?
Yes, that's white, with every channel at its maximum. #000000 is rgb(0, 0, 0), pure black, with every channel at zero.
Is my color uploaded anywhere?
No. The conversion is arithmetic that runs in your browser, and the hex you type stays on your device.
What color space does it assume?
sRGB, the standard space a hex or rgb() value implies on the web. Wide-gamut colors are not remapped; they are read as ordinary sRGB numbers.

References

Because a hex color is RGB written in base 16, you can check any result yourself: run it back through RGB to HEX and you land on the code you started with.

RGB to HEX Converter

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

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 HEX to RGB Converter

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