
How the hex-to-RGB formula works
The hex to RGB formula is: expand any short CSS hex form, split the color into red, green, and blue byte pairs, then calculate each channel as (first hex digit × 16) + the second hex digit.
In CSS hexadecimal notation, every 8-bit channel is represented by two base-16 digits. The digits 0 through 9 represent decimal values 0 through 9, while A through F represent 10 through 15. A complete pair therefore maps to an integer from 0 through 255, which is the range used by RGB channels.
For six-digit notation #RRGGBB, apply the calculation to each pair in channel order:
- Red = (first R digit × 16) + second R digit.
- Green = (first G digit × 16) + second G digit.
- Blue = (first B digit × 16) + second B digit.
In compact form, the rule is channel byte = 16 × high nibble + low nibble. The high nibble is the first digit, and the low nibble is the second. The leading hash is a CSS prefix rather than part of the numerical conversion.
| CSS form | Component order | Expansion rule | Alpha |
|---|---|---|---|
| #RGB | Red, green, blue | Duplicate each one-digit component | Not included |
| #RGBA | Red, green, blue, alpha | Duplicate each one-digit component | Included |
| #RRGGBB | Red, green, blue | Already two digits per component | Not included |
| #RRGGBBAA | Red, green, blue, alpha | Already two digits per component | Included |
Uppercase and lowercase letters have the same numerical meaning. Three- and six-digit values do not specify alpha and are treated as fully opaque for the preview, while four- and eight-digit values carry transparency information.
Work through one complete conversion
Consider the CSS color #1A73E8. Its six digits divide into the red pair 1A, green pair 73, and blue pair E8.
- The red pair 1A contains the digits 1 and 10, so 1 × 16 + 10 = 26.
- The green pair 73 contains the digits 7 and 3, so 7 × 16 + 3 = 115.
- The blue pair E8 contains the digits 14 and 8, so 14 × 16 + 8 = 232.
Putting those byte values in red, green, and blue order produces rgb(26, 115, 232). Because this six-digit color contains no alpha component, its preview is fully opaque.
Alpha is a fourth channel, not a prefix
CSS four-digit and eight-digit hexadecimal colors place alpha last. After parsing the red, green, and blue bytes, read the final byte as alpha and calculate its opacity with this formula: opacity = alpha byte ÷ 255. The alpha byte itself remains an integer from 0 through 255.
Some hexadecimal conventions outside CSS place opacity first. The converter does not interpret #AARRGGBB as a CSS color and does not reorder the components based on how a color appears. If the source is intended to use CSS notation, verify that its transparency byte comes after blue.
A readable CSS alpha value uses up to three decimal places, with trailing zeros removed, while the exact alpha byte and normalized eight-digit HEX remain visible. The displayed percentage is rounded to two decimal places. This rounding does not modify the normalized HEX value, so retain that value when a translucent color must survive an exact round trip.
The W3C CSS Color Level 4 hexadecimal notation defines the component order used by CSS hexadecimal colors. Four-digit forms apply the same nibble-duplication rule to every component, including alpha, before the resulting bytes are interpreted.
Convert a CSS HEX color in the browser
- Paste the color into the HEX to RGB Converter. The input must begin with # and contain exactly three, four, six, or eight hexadecimal digits. Ordinary whitespace around the complete value is trimmed, but spaces inside it are not accepted.
- Read the normalized lowercase HEX, CSS rgb() or rgba() string, individual channel bytes, and alpha value. Confirm that the byte order is red, green, blue, followed by alpha when an alpha component is present.
- Check the live preview for an obvious channel-order error. For translucent colors, retain the exact alpha byte or normalized eight-digit HEX when precision matters. Invalid or empty input replaces the previous conversion with a clear error rather than leaving a stale successful result on screen.
Conversion is immediate and runs entirely in the current browser. The color string is not uploaded to Lizely, so the parsing and preview work stays local to the browser session.
Choose the output that matches the destination
The same color can be represented in several forms, but each output serves a different purpose. Choose based on what will consume the value and how much precision that system requires.
| Output | Best use | Precision or handling note |
|---|---|---|
| Normalized HEX | Source values and exact round trips | Retain the complete hash and any alpha byte |
| CSS rgb() or rgba() | Stylesheets that accept CSS color functions | Readable alpha may use rounded decimal notation |
| Individual channel bytes | APIs, canvas operations, image editors, tests, and design tokens | Use integer red, green, blue, and optional alpha values from 0 through 255 |
| Live preview | Checking an obvious color or channel-order mistake | Not a color-management or print reference |
Use the CSS output directly in style rules. Use the separate channel values when an application expects distinct red, green, blue, or alpha inputs. Keep the normalized HEX whenever the source must be reconstructed exactly, especially when a short decimal cannot represent the alpha byte precisely.
CSS syntax boundaries that affect the result
The converter follows CSS hexadecimal notation strictly rather than accepting every shorthand that a design application might tolerate.
- The leading # is required. Missing hashes, doubled hashes, incorrect lengths, embedded whitespace, and characters outside 0 through 9 and A through F are rejected.
- Only four-digit #RGBA and eight-digit #RRGGBBAA forms include alpha. The tool does not silently guess an alternative component order.
- Named colors, hsl(), lab(), lch(), color(), system colors, CSS variables, gradients, and comma-separated palettes are outside the converter’s accepted input.
- The parser does not convert between color spaces, measure contrast, choose an accessible foreground, or sample colors from an image.
The MDN hex-color reference provides the corresponding CSS syntax and examples. Keeping the complete CSS token, including its hash, makes the intended value easier to validate at each handoff.
What the preview does—and does not—prove
The preview renders the generated CSS color in the browser. It is useful for catching an obvious mistake, such as swapping red and blue, but it does not prove that the color will look identical on every display.
Screens, browser profiles, display brightness, ambient light, and wide-gamut workflows can all affect how the same numeric sRGB color appears. The preview is therefore not a color-management reference, and hexadecimal CSS values are not Pantone, CMYK, printer ink recipes, or physical color measurements.
Use a dedicated contrast tool for an accessibility ratio and a separate RGB-to-CMYK workflow for a basic process-color estimate. Print production still requires a managed profile and proofing workflow.
A dependable handoff checklist
Before using the converted value, run through these checks:
- Copy the complete CSS token, including its leading #.
- Confirm that it has three, four, six, or eight hexadecimal digits.
- Verify that the expected channels are red, green, blue, and optional final alpha.
- Compare the displayed channel bytes with the system that will consume them.
- Retain normalized eight-digit HEX when sharing a translucent color that requires exact round-trip precision.
This workflow keeps the numerical conversion deterministic while making clear which part of the result is appropriate for CSS, which part is appropriate for an API or design token, and where additional visual or production verification is still needed.
Related reading: Convert RGB to CMYK in CorelDRAW: A Practical Guide.
Related reading: Are My Color Values Uploaded When I Convert RGB to HEX?.