To convert HEX to RGB in CSS, split a valid CSS hexadecimal color into red, green, blue, and optional alpha bytes, then express red, green, and blue as decimal values from 0 to 255 in an rgb() or rgba() function. For transparency, divide the final alpha byte by 255. The HEX to RGB Converter performs this strict CSS conversion and displays normalized lowercase HEX, CSS output, individual channel bytes, and a live preview without uploading the color string.

CSS hex forms the converter accepts
CSS hexadecimal colors use a required hash followed by exactly 3, 4, 6, or 8 ASCII hexadecimal digits. Letters A through F and digits 0 through 9 are accepted, and uppercase and lowercase letters have the same meaning. This notation follows the W3C CSS Color Module Level 4 hexadecimal specification and the format documented by MDN’s hex-color reference.
| CSS form | Component order | Alpha handling |
|---|---|---|
| #RGB | Red, green, blue | No alpha is specified; the preview is fully opaque. |
| #RGBA | Red, green, blue, alpha | The final component contains transparency. |
| #RRGGBB | Red, green, blue | No alpha is specified; the preview is fully opaque. |
| #RRGGBBAA | Red, green, blue, alpha | The final component contains transparency. |
Short notation expands by duplicating each hexadecimal digit, while long notation uses two digits for every channel. Each completed component is an integer byte from 0 through 255. The converter trims ordinary whitespace around the complete value, but it does not accept spaces inside the token. It also rejects a missing hash, an incorrect digit count, doubled hashes, and characters outside the hexadecimal alphabet.
Convert a hex color for a CSS stylesheet
The conversion is immediate, but checking each part of the result helps prevent a valid color from being interpreted in the wrong order or copied with unnecessary precision loss.
- Paste the complete CSS token. Include the leading # and use a 3-, 4-, 6-, or 8-digit form without embedded spaces. Paste the value into the HEX to RGB Converter and confirm that the input is accepted.
- Read the normalized HEX and CSS output. The normalized value expands shorthand notation into its lowercase six- or eight-digit form. Inputs without alpha produce CSS rgb() output, while four- and eight-digit inputs produce rgba() output that includes transparency.
- Check the individual channel bytes. Read the red, green, and blue integers in that order. Use these exact values when an API, canvas operation, image editor, test fixture, or design-token system expects separate RGB channels rather than one CSS color string.
- Review transparency and the preview. For a translucent color, keep the exact alpha byte visible and retain the normalized eight-digit HEX value when an exact round trip matters. Use the live preview as a quick visual check, especially for an obvious channel-order error.
An invalid or empty input replaces the previous conversion with a clear error. That behavior prevents an old successful result from being mistaken for the result of the value currently in the input field.
Channel conversion in one CSS example
Consider the CSS color #3B82F6. Each two-digit pair is read as a base-16 number:
- Red: 3B = (3 × 16) + 11 = 59
- Green: 82 = (8 × 16) + 2 = 130
- Blue: F6 = (15 × 16) + 6 = 246
RGB = (red byte, green byte, blue byte) = (59, 130, 246), so the corresponding CSS declaration is color: rgb(59, 130, 246);. This calculation also shows why component order must be preserved: the first pair is red, the second is green, and the third is blue.
Choose the output that matches your workflow
The converter exposes several representations because a readable CSS value and an exact machine-readable value do not always serve the same purpose.
| Output | Best for | Important detail |
|---|---|---|
| Normalized HEX | Sharing a color, preserving a canonical source value, or making an exact round trip | Shorthand input is expanded into lowercase six- or eight-digit notation. |
| CSS rgb() or rgba() | Stylesheets that accept CSS functional color notation | A translucent alpha decimal is rounded for readability. |
| Individual channel bytes | APIs, canvas code, image editors, test fixtures, and design tokens | Red, green, and blue are exact integers from 0 through 255. |
| Live preview | Checking the generated color and obvious channel-order mistakes | It is not a color-management reference, so screen appearance can vary. |
Use the CSS function when the destination is a stylesheet. Use the channel values when separate integer inputs are required. Keep the normalized HEX when the source must survive a round trip without depending on a rounded decimal alpha.
Keep CSS alpha in the final byte
CSS uses #RRGGBBAA, so alpha is the last byte after red, green, and blue. Some eight-digit color conventions used outside CSS place opacity first, but the converter does not interpret #AARRGGBB as a CSS color and never reorders an input based on how it appears visually.
The opacity formula is alpha byte ÷ 255. For a readable rgba() value, a non-endpoint alpha is displayed to three decimal places with trailing zeros removed. The exact alpha byte remains visible beside it, and the percentage view is shown to two decimal places. That display rounding does not modify the normalized eight-digit HEX value, but a short decimal can represent the alpha only approximately.
Three- and six-digit colors do not specify alpha and are treated as fully opaque for the preview. Four- and eight-digit colors include transparency. If a translucent value will pass through several systems, verify that each one follows CSS’s alpha-last order and retain the source HEX alongside any rounded rgba() output.
Apply the result in a stylesheet
Place the generated CSS function after the property name and colon. An opaque conversion can be used like color: rgb(59, 130, 246);, while a translucent conversion uses the displayed rgba() value.
- Use the complete rgb() or rgba() output rather than mixing individual decimal channels with the original shorthand.
- When assigning the result to a CSS custom property, place the generated function after the variable’s colon. The converter does not accept a CSS variable as its input, but its output can still be used as the variable’s value.
- Compare the alpha in the rgba() output with the exact alpha byte shown by the converter before publishing a translucent design token.
- Check the color in the browser page where it will be used. The preview can expose an obvious mistake, but ambient light, display brightness, browser profiles, and wide-gamut workflows can still make the same sRGB values look different.
Validation and conversion boundaries
The converter is deliberately limited to CSS hexadecimal notation. It does not parse named colors such as rebeccapurple, hsl(), lab(), lch(), color(), system colors, CSS variables, gradients, or comma-separated palettes. It also does not sample colors from images, measure contrast, select an accessible foreground, convert between color spaces, or determine whether two displayed colors are identical.
Hexadecimal CSS colors represent sRGB channel values rather than Pantone references, CMYK ink recipes, or physical measurements. For a basic process-color estimate, the RGB to CMYK Converter can provide an approximate starting point, but dependable print production still requires a managed profile and proofing workflow. If the next task is checking readable text against a background, use the converted RGB values with the Color Contrast Checker because the HEX converter itself does not calculate contrast ratios.
Parsing, validation, formatting, and preview rendering all happen locally in the current browser, and the color string is not uploaded. This keeps the workflow suitable for checking private or unreleased design values without sending them to a remote conversion service.
For a deeper look, see Using HTML Color Names in CSS: Aliases and Examples.
For a deeper look, see RGB to Hexadecimal Formula: A Practical Checklist.