To convert hex to RGB, paste a CSS hexadecimal color such as #1e90ff into a converter that understands the four CSS forms: #RGB, #RGBA, #RRGGBB, and #RRGGBBAA. The tool parses the leading hash, splits the remaining digits into red, green, blue, and optional alpha bytes, and returns a normalized lowercase hexadecimal string, an rgb() or rgba() CSS value, and the individual 0–255 channel integers. Alpha is always the last byte in CSS notation and is divided by 255 to produce the 0–1 opacity used in rgba(). The whole conversion runs locally in the browser, so the color string is never uploaded. The HEX to RGB Converter follows this exact contract and surfaces each part of the result so you can copy whichever representation your stylesheet, canvas call, or design token needs.

how to convert hex to rgb
how to convert hex to rgb

What CSS Hexadecimal Notation Actually Is

A CSS hex color is a string that begins with # and is followed by exactly three, four, six, or eight hexadecimal characters. Each pair of characters represents one byte, so #RRGGBB encodes red in the first byte, green in the second, and blue in the third. The shorter #RGB form uses one nibble per channel and is expanded by duplicating each digit, which is why #1e9 and #11ee99 are the same color. When an alpha channel is present, CSS appends it as the final byte: #RRGGBBAA. This ordering matters because some eight-digit color conventions used outside web CSS place alpha first, but the converter strictly follows CSS semantics and never reorders the bytes.

Hexadecimal digits range from 0 to 9 and from A to F, where A means ten and F means fifteen. Two digits together cover 0 (00) to 255 (FF), which matches the integer range of each sRGB channel. Alpha follows the same byte range: 00 is fully transparent and FF is fully opaque. When you see 0.5 in an rgba() string, that is the byte 128 (hex 80) divided by 255, not a separate kind of measurement.

Accepted Hex Formats

The converter accepts every CSS-defined hex form. The table below summarizes each accepted length, what it expands to, and whether it carries alpha.

InputDigits after #Expansion ruleIncludes alpha
#RGB3Duplicate each nibble (#1e9 → #11ee99)No, treated as fully opaque
#RGBA4Duplicate each nibble (#0f08 → #00ff0088)Yes, last byte
#RRGGBB6No expansion neededNo, treated as fully opaque
#RRGGBBAA8No expansion neededYes, last byte

Uppercase and lowercase letters are equivalent, so #FF5733 and #ff5733 produce the same channels. The parser also trims ordinary whitespace around the complete value, but it refuses anything that breaks the strict grammar: a missing hash, an incorrect length, a doubled hash, an embedded space, or a character outside 0–9 and A–F. When input fails, the tool clears the prior conversion rather than silently guessing what the author intended.

How to Convert Hex to RGB

  1. Paste a CSS hex color beginning with # in three-, four-, six-, or eight-digit form. For example, type #1e90ff into the converter. The leading hash is required and the digits must be 0–9 or A–F. Three- and four-digit shorthand such as #1e9 and #0f08 are also valid and are expanded automatically.
  2. Read the normalized hexadecimal value, CSS rgb() or rgba() string, and individual channel values. The normalized form is always lowercase and uses the expanded digit count, with eight digits when alpha is present. The CSS string uses rgb() for opaque colors and rgba() for translucent ones, and the channel bytes appear as separate integers in the 0–255 range so they can be copied into canvas calls, image editors, or test fixtures.
  3. Check the live preview and, for translucent colors, retain the alpha byte when exact round-trip precision matters. The preview uses the browser's CSS color rendering to confirm you typed what you meant, but the numeric channels are the part that travels to other systems. If the alpha value matters, copy the normalized #RRGGBBAA hex rather than the rounded decimal, because decimal alpha can lose a small amount of precision when the byte is not exactly representable in three places.

Reading the Output Fields

Each conversion surfaces the same handful of values. The table below shows what each field is for and when to copy it.

Output fieldWhat it representsWhen to copy it
Normalized HEXLowercase expanded #RRGGBB or #RRGGBBAAStylesheets, design tokens, exact round-trips
CSS rgb() or rgba()Browser-ready string with decimal alphaInline styles, CSS variables, canvas APIs that expect CSS strings
Red, Green, Blue bytesIndividual 0–255 integersCanvas calls, image editor inputs, test fixtures, design tokens needing integer channels
Alpha byte (0–255) and opacity (0–1)Alpha as an integer and as byte/255APIs that need an integer alpha; styles that need rgba()
Live preview swatchBrowser-rendered color from the generated CSSVisual sanity check that channels were typed in the right order

How Short Notation Expands (Worked Example)

Short hex notation is purely a typing shortcut, not a separate color space. Take #123 as the input. Each nibble is duplicated to form a six-digit color, so #123 expands to #112233. From there, the red byte is the first pair (11 in hex), the green byte is 22, and the blue byte is 33. Converting each pair to decimal gives red = 17, green = 34, blue = 51. The same expansion rule applies to four-digit shorthand with alpha, where the last nibble of the input becomes the last byte of the eight-digit output. Doing this by hand for every color you encounter is tedious, which is why a CSS hex to RGB converter handles both the duplication and the base conversion in one step.

Why Alpha Sits at the End in CSS

CSS places alpha as the final byte, so #RRGGBBAA reads red, green, blue, then transparency. Some non-CSS conventions reverse this and use #AARRGGBB, which is the order used in older Android resource values. The converter never interprets the first byte of an eight-digit value as alpha, even if the resulting color happens to look plausible. If you paste a token that uses #AARRGGBB, the alpha byte is being read as red, and the displayed channels will not match the source. For translucent web colors, always confirm the source uses CSS's alpha-last order and, when sharing an exact value, copy the normalized eight-digit hex so no rounding is lost.

Alpha decimals are also worth understanding. CSS expresses alpha as a number between 0 and 1, so a byte of 80 (hex) becomes 128 divided by 255, which the converter renders as approximately 0.502. The readable rgba() output trims trailing zeros and rounds to three decimal places, while the exact byte and the normalized hex remain visible alongside it. The endpoints are exact: 00 maps to 0 and FF maps to 1, with no rounding involved. If a downstream system requires that exact opacity, use the byte or the hex rather than the rounded decimal, because a short decimal alpha can lose a small amount of precision even though the numeric color stays correct to the eye.

Input Mistakes the Converter Catches

Because the parser follows strict CSS hex grammar, several common mistakes surface as visible errors rather than silent guesses:

  • Missing leading hash. 1e90ff is rejected because the parser requires #1e90ff.
  • Wrong number of digits. A five- or seven-character string after the hash does not match any valid CSS form and is refused.
  • Doubled hash. Strings like ##1e90ff or #1e#90ff contain characters outside the hex alphabet and are not accepted.
  • Embedded whitespace. #1e 90ff is rejected, although ordinary whitespace around the complete value is trimmed.
  • Non-hex characters. Letters outside A–F, punctuation, or digits that exceed F are refused.

Invalid or empty input replaces the prior conversion with a clear error, so a stale successful result is never presented as though it belongs to the current value. This matters when iterating through a list of colors, because the displayed channels always correspond to whatever is currently in the input field.

When You Need More Than RGB Channels

Hex and RGB describe the same sRGB numbers in two different notations, which is why converting between them is lossless. Other color workflows live outside that simple mapping. If you need a foreground and background that meet WCAG contrast targets, the Color Contrast Checker computes the ratio from the channel values for you. If you are designing for print, the same numeric sRGB color is not a Pantone, a CMYK recipe, or a physical ink measurement; the RGB to CMYK Converter gives a quick process-color estimate, but production work still needs a managed profile and proofing. For the reverse direction, converting RGB to HEX in your browser uses the same channel bytes in the opposite order. If you want the formal grammar this converter implements, the W3C CSS Color Module Level 4 hexadecimal notation and the MDN hex-color reference document the same #RGB, #RGBA, #RRGGBB, and #RRGGBBAA forms.