HEX to RGB Converter
The HEX to RGB Converter turns any hex color code into its red, green, and blue channel values — handling 3-digit shorthand, 6-digit codes, and 8-digit hex with alpha. Perfect when your design file says #3b82f6 but your code needs rgb().
How to Use
- 1
Paste a hex code like #3b82f6 into the input — with or without the #, in 3-digit (#fff), 6-digit, or 8-digit alpha form.
- 2
The red, green, and blue channel values (0–255) appear instantly, plus the alpha channel when your hex includes one.
- 3
Copy the result as rgb(59, 130, 246) for CSS, or grab the individual channel numbers for canvas, WebGL, or design tools.
- 4
Copy the rgb() or rgba() result with the copy button next to it.
Frequently Asked Questions
Do I need the # at the start?
What about 8-digit hex like #3b82f680?
Why do I need RGB when hex already works in CSS?
Is the conversion exact or lossy?
Why is the rgba() line shown even for a 6-digit code?
How precise is the alpha value?
What do the error messages mean?
Can I paste a named color like tomato?
What does the Reset button do?
Does it work offline?
Generative Answer & AI Documentation
What is the HEX to RGB Converter?
The HEX to RGB Converter turns a hex color code into the red, green, and blue channel values that canvas, WebGL, SVG filters, and programmatic color math actually consume. Paste a code such as #3b82f6 and the tool shows rgb(59, 130, 246) and rgba(59, 130, 246, 1) instantly, each with its own copy button. It accepts three lengths: 3-digit shorthand (#fff expands to #ffffff), standard 6-digit codes, and 8-digit codes where the final two digits are the alpha channel — #3b82f680 becomes rgba(59, 130, 246, 0.5). The hash is optional, so 3b82f6 works as well as #3b82f6. Invalid input is not silently ignored here: a code of the wrong length produces the message "Hex code must be 3, 6, or 8 characters." and non-hex characters produce "Invalid hex values.", with the outputs cleared until the input is fixed. A Reset button restores the default #6366f1. The conversion runs entirely in your browser — hex is base-16 shorthand for the same three channel numbers, so the arithmetic is exact and nothing is uploaded.
Why use HEX to RGB Converter offline?
Hex is the format design tools speak, but it is not the format code speaks. A canvas gradient, a WebGL shader, an SVG filter, and any code that mixes, darkens, or blends colors all operate on channel values from 0 to 255 — and a hex string is useless to them until it is split into those three numbers. Doing that split by hand means converting base-16 pairs in your head, which is slow and easy to get wrong, especially under the pressure of a design handoff. This tool does the split instantly and exactly, and it is the only converter on this site that handles the 8-digit form: when a design token carries transparency as #3b82f680, this is the page that turns it into the rgba() value your CSS needs. Because the conversion is lossless — hex and RGB are two writings of the same numbers — the values you copy are the values your design file meant, with no rounding drift to chase later.
When should you use this tool?
Use it when a design file, a brand guide, or a Figma inspection panel gives you a hex code and the destination needs numbers: a canvas 2D gradient stop, a WebGL uniform, an SVG filter, a charting library's color option, or a function that darkens a color by scaling its channels. Use it when the hex carries alpha — an 8-digit token from a design system — and you need the rgba() form for CSS. Use it when you need the individual channel numbers themselves, for example to feed a color-mixing function or to compare two colors channel by channel. Do not use it when the destination is a stylesheet that accepts hex directly — in that case there is nothing to convert — and do not use it for named colors or rgb() strings, which it does not parse; the full Color Converter is the page for translating between formats generally.
Key Benefits
- Three hex lengths: 3-digit shorthand, 6-digit codes, and 8-digit hex with an alpha channel.
- Both outputs at once: rgb() and rgba() are shown side by side, each with its own copy button.
- Alpha handled properly: the last two digits of an 8-digit code become a 0–1 opacity value in the rgba() output.
- Clear error messages: wrong length or non-hex characters produce a specific message instead of a silent wrong answer.
- Hash optional: #3b82f6 and 3b82f6 both work, and shorthand expands automatically.
- Exact and lossless: hex is base-16 for the same channel values, so the conversion is fully reversible with no rounding.
Common Use Cases
- Feeding a canvas gradient: a design token says #3b82f6 — convert it to rgb(59, 130, 246) for a createLinearGradient color stop.
- Writing a translucent overlay: an 8-digit token #3b82f680 becomes rgba(59, 130, 246, 0.5) for a CSS overlay or box-shadow color.
- Building a color-mixing function: pull the three channel numbers out of a brand hex so code can darken or blend it programmatically.
- Matching a WebGL shader uniform: convert the brand hex to 0–255 channels before normalising them for the shader.
- Checking a design token: paste a token's hex and confirm the channels are what the design system documents.
Developer Notes & Best Practices
The parser strips whitespace and an optional leading #, then expands a 3-digit code by doubling each digit (#fff becomes #ffffff). Only lengths of 3, 6, or 8 are accepted after expansion — anything else sets the error "Hex code must be 3, 6, or 8 characters." and clears both outputs. Each pair of hex digits is parsed as a base-16 number from 0 to 255; if any pair is not valid hex, the error is "Invalid hex values." For 8-digit codes, the final pair is the alpha channel, converted to a 0–1 value by dividing by 255 and rounding to two decimal places — 0x80 (128) becomes 0.5, 0xFF becomes 1, and 0x00 becomes 0. The rgba() line is always shown, even for 6-digit input, where the alpha is simply 1. Because hex is only a notation for the channel numbers, the conversion is exact for the RGB channels: #3b82f6 and rgb(59, 130, 246) are the same color written two ways, and converting back reproduces the original hex. The tool starts on #6366f1, which is rgb(99, 102, 241) and rgba(99, 102, 241, 1).
- Paste the hex exactly as the design file gives it, with or without the #: the tool strips the hash and expands shorthand automatically.
- For translucent colors, use the 8-digit form and copy the rgba() line: the rgb() line alone drops the transparency.
- Check the alpha rounding: the opacity is rounded to two decimals, so an unusual alpha such as 0x33 becomes 0.2 — confirm that is the opacity your design intended.
- If the outputs disappear, read the error line: a wrong-length code and a non-hex character are different problems with different messages.
- Use the Reset button to return to #6366f1 when you want a known-good value to sanity-check the tool before converting a batch of tokens.
Common Mistakes
- Pasting an rgb() string into the hex field: this tool parses hex only, so rgb(59, 130, 246) produces "Invalid hex values." — type the three channel numbers into the RGB to HEX Converter instead, or use the full Color Converter.
- Reading the alpha digits as part of the color: in #3b82f680 the final 80 is opacity (0.5), not a fourth color channel — the rgb() line correctly ignores it and only the rgba() line carries it.
- Copying the rgb() line for a translucent color: rgb(59, 130, 246) drops the alpha, so a semi-transparent token pasted as rgb() becomes fully opaque — copy the rgba() line.
- Typing a 4-digit or 5-digit code: only 3, 6, and 8 digits are valid, and anything else clears the outputs with the length error — count the digits before assuming the tool is broken.
- Expecting the alpha to be a percentage: the rgba() output uses a 0–1 opacity (0.5), not 50 — writing rgba(59, 130, 246, 50) in CSS is invalid.
Limitations
Only hex codes are accepted as input — named colors, rgb() strings, and hsl() strings are not parsed, and there is no color picker on this page. The alpha value is rounded to two decimal places, so an 8-digit hex with an unusual alpha loses a little precision in the rgba() output. There is no batch mode: one hex code converts at a time, so a whole token file has to be converted one value at a time. The page shows no preview swatch, so you cannot confirm the color by eye here — use the full Color Converter or the RGB to HEX Converter when you want to see the color. The tool does not validate that an 8-digit alpha is one your design system actually uses; it converts whatever digits you give it.
Structured Input/Output Example
#3b82f680
RGB: rgb(59, 130, 246) RGBA: rgba(59, 130, 246, 0.5)
Related Tools
Color Converter
Color converter: translate colors between HEX, RGB, HSL and OKLCH with a live preview swatch. Type a hex code or pick visually, then copy clean CSS.
RGB to HEX Converter
RGB to hex converter: turn RGB channel values into compact hex codes like #3b82f6 in one step. Free, offline, private.
RGB to HSL Converter
RGB to HSL converter: translate RGB colors into hue, saturation, and lightness — the way humans think about color. Build hover states and palettes easily.