HEX to RGB Converter

Convert HEX to RGB as you type — free, instant, with a worked example and a common-colors chart.

Worked example

HEX #ff5733 = RGB 255, 87, 51

ff → 255 · 57 → 87 · 33 → 51

How the conversion works

  • A HEX code is the same three RGB channels written in base-16: two digits per channel, from 00 (0) to ff (255).

Common colors in HEX and RGB

ColorHEXRGB
Red#ff0000255, 0, 0
Orange#ffa500255, 165, 0
Yellow#ffff00255, 255, 0
Green#0080000, 128, 0
Cyan#00ffff0, 255, 255
Blue#0000ff0, 0, 255
Purple#800080128, 0, 128
Pink#ffc0cb255, 192, 203
Brown#a52a2a165, 42, 42
White#ffffff255, 255, 255
Gray#808080128, 128, 128
Black#0000000, 0, 0

Every conversion runs in your browser. Nothing you enter is uploaded to BroBroGo.

FAQ

How do I convert HEX to RGB?

Type or paste your HEX value above — the RGB value updates as you type. You can also pick the color visually with the swatch.

Is the conversion exact?

Yes — HEX and RGB are the same three channels written differently, so converting between them is exact in both directions.

How the HEX‑to‑RGB Conversion Works

The core of this page is a deterministic, mathematical transformation. A HEX color code is a base‑16 (hexadecimal) representation of three 8‑bit channels: red, green, and blue. Each channel in a six‑digit code uses two hex digits, giving 16² = 256 possible values, from 0 to 255 in decimal. The conversion follows a simple polynomial:

For a pair like 4f, the left digit represents the “sixteens” place and the right digit the “ones” place. So 4f = 4 × 16 + 15 = 64 + 15 = 79. The same arithmetic applies to the green pair (46 → 4×16 + 6 = 70) and the blue pair (e5 → 14×16 + 5 = 229). The result is the RGB triplet (79, 70, 229).

Because this is a pure base conversion—no rounding, no gamut mapping—the relationship is reversible. You can take any RGB value and express it back as a six‑digit HEX without loss. The page does not introduce any scaling or clipping; the output is always exact integers between 0 and 255.

When you enter a three‑digit shorthand like #abc, the page automatically doubles each digit: a becomes aa, b becomes bb, c becomes cc, yielding #aabbcc. That expanded form is then processed exactly as a six‑digit code. The doubling rule is defined by the CSS Color Module Level 4 and is the standard way browsers interpret shorthand hexadecimal colors.

Input Rules and Accepted Formats

The tool is strict about what it accepts as a valid HEX color code. The acceptable patterns are:

  • #RRGGBB – a hash symbol followed by exactly six hexadecimal digits (0–9, A–F, case insensitive). Example: #4f46e5.
  • RRGGBB – six digits without the hash. The tool treats the hash as optional. Example: 4f46e5.
  • #RGB – a hash followed by three hex digits, which are expanded to six. Example: #abc becomes #aabbcc.
  • RGB – three digits without the hash, also expanded. Example: abc becomes aabbcc.

Any input that does not match one of these four patterns triggers the error message:
"Enter a hex color like #4f46e5 or #abc."
This includes entries with extra characters (e.g., #4f46e5!), fewer than three digits, more than six digits (except eight‑digit codes with alpha, which are not supported), or non‑hexadecimal symbols like g or z.

The page does not accept:

  • Eight‑digit HEX codes with alpha (#RRGGBBAA) – the tool is built for three channels only.
  • Named colors (red, blue) – the input expects raw hex digits.
  • RGB functional notation (rgb(255,0,0)) – that is a different format and belongs on a different conversion page.

Built‑in Color Picker

You can also use the provided color picker to choose a color visually. That action writes a six‑digit HEX code (with hash) into the input field, and all conversions happen immediately. The picker is a convenience to avoid typing, but the underlying conversion logic remains the same.

Real‑Time Updates and Related Color Models

Editing any color field triggers an instant update of all other fields displayed on the page. This includes:

Color model Example output for #4f46e5
RGB 79, 70, 229
HSL hsl(243, 75%, 59%)
HSV hsv(243, 69%, 90%)
CMYK cmyk(65%, 69%, 0%, 10%)
LAB lab(34, 42, -65)

The conversions between models are algorithmic and deterministic. For instance, the HSL calculation uses the standard RGB‑to‑HSL formulas from the CSS Color specification. The LAB values are derived via an intermediate linear‑RGB and the CIE XYZ space (using the D65 illuminant and a 2° standard observer). All math is performed in your browser (JavaScript); no data is sent to a server.

This real‑time linkage means you can experiment: change the blue channel in RGB and watch the LAB lightness change, or adjust hue in HSL and see the HEX code update. The page functions as a cross‑model color converter optimized for the HEX‑to‑RGB entry point.

Why This Conversion Exists

A frequent question is: why bother converting HEX to RGB when both are widely supported? The answer lies in where and how the color values are used.

  • In CSS, both #ff6600 and rgb(255, 102, 0) are valid and produce the exact same screen output. But some CSS functions like rgba() or color-mix() work with numerical channel values. If you have a HEX code from a design mockup, you need to convert it to RGB before plugging it into an rgba() call that includes transparency.
  • JavaScript canvas APIs (Canvas 2D, WebGL) expect colors as RGB triplets (or RGBA quads). The fillStyle and strokeStyle properties accept CSS color strings, but many libraries and functions (e.g., ImageData, pixel‑manipulation loops) operate on arrays of numeric 0–255 values. You cannot pass #ff6600 directly into an ImageData.data array.
  • Color mixing and math is more natural in RGB. To blend two colors or compute contrast ratios, you need the decimal channel values. The hexadecimal representation is convenient for humans but not for arithmetic.
  • Design tools (Figma, Sketch, Photoshop) often show both HEX and numeric RGB sliders. If your brand guidelines specify only a HEX code, you need the RGB numbers to set the sliders precisely.

This page is designed precisely for that transition: it takes the compact, human‑readable HEX and produces the exact decimal channels that software and algorithms expect.

Common Pitfalls and Edge Cases

Even though the conversion is mathematically trivial, people make mistakes when doing it by hand or with ad‑hoc tools. The page handles these reliably:

1. Shorthand ambiguity

A three‑digit code like #abc is not a shortened form of #a0b0c0. The doubling rule (aaa) gives #aabbcc. Some beginners expand incorrectly, for example reading #abc as #aabbcc but then interpreting aa as a*10 + a*120, which is wrong. The correct interpretation is hexadecimal: aa = 10×16 + 10 = 170.

2. Missing hash and case sensitivity

The hash # is optional. FF6600 is valid and treated the same as #FF6600. Case is not important: 1E90FF and 1e90ff produce the same RGB values. The page converts letters automatically to uppercase internally before parsing, but shows the result in lowercase for consistency if desired.

3. Invalid characters

Characters outside the hexadecimal range (0–9, A–F/a–f) are rejected. For example, #GGG triggers the error. So does #1234567 (seven digits) or #12 (only two digits). The error message is specific: "Enter a hex color like #4f46e5 or #abc." This covers both six‑digit and three‑digit formats.

4. Eight‑digit HEX (with alpha)

The page does not support #RRGGBBAA. If you paste #4f46e580 (a semi‑transparent version of the example), the tool will show the error. This is by design: the page is a dedicated HEX‑to‑RGB converter, not an RGBA converter. For alpha handling, you would need a separate page that strips the alpha or converts to rgba().

5. Rounding illusion

Because the conversion uses exact integer arithmetic, there is no rounding. However, when the page displays RGB values, they are always integers. If you manually convert #808080 to RGB, you get 128, 128, 128 – exactly half of 255, not 127.5 or 128 after rounding. The conversion is lossless.

Practical Use Cases

  • Front‑end developers writing dynamic styles in JavaScript can copy the RGB values from this page directly into template literals like rgb(${r},${g},${b}) or into an array for a canvas pixel buffer.
  • Designers who receive brand colors as HEX can type them here, then read the RGB equivalents to set sliders in their design software that doesn’t accept HEX. They also get HSL and HSV values for adjusting hue or saturation.
  • Students learning color models can enter any HEX and observe how the three 8‑bit channels combine. For example, #FF0000 yields (255,0,0) – the maximum red value, with green and blue at zero. Changing to #FF00FF shows magenta (full red and full blue, no green).
  • Accessibility testers can compute luminance from the RGB values (using the relative luminance formula: 0.2126×R + 0.7152×G + 0.0722×B, with gamma‑corrected sRGB values). Having the exact 0–255 channels simplifies that calculation.
  • Game developers often need to pack colors into 32‑bit integers (8 bits per channel, plus alpha). They can take the RGB from this page and shift the bits accordingly: (r << 16) | (g << 8) | b.

FAQ

Why does a three‑digit code like #abc expand to #aabbcc instead of #a0b0c0?

The CSS specification defines shorthand expansion by doubling each digit. This gives a denser, more saturated color than inserting zeros. The rule ensures that #abc is a valid way to write the same color as #aabbcc, not a dimmer version.

Can I use lowercase letters in the HEX code?

Yes. The tool treats uppercase and lowercase hexadecimal digits equivalently. #4f46e5 and #4F46E5 produce the same RGB result.

What happens if I type a hex code with an alpha channel like #ff0000aa?

The page will show the error message because it expects exactly six digits (or three for shorthand). Eight‑digit codes are not supported on this page. You would need a separate converter that handles alpha.

How are the HSL and LAB values calculated?

HSL is derived from the 0‑255 RGB values using the standard algorithm: normalizing to 0‑1, finding min/max, and computing hue as an angle, saturation as a percentage, and lightness as a percentage. LAB uses a linearization to the sRGB transfer curve, conversion to CIE XYZ (D65 illuminant), and then the CIE Lab transformation. All calculations are performed in JavaScript within your browser.

The page shows RGB as three numbers separated by commas. Where can I use that format directly?

You can use it in CSS rgb(79, 70, 229), in canvas context.fillStyle = 'rgb(79,70,229)', or in almost any programming language that accepts RGB tuples. Some environments expect a space separator instead of commas; you can easily replace the commas with spaces after copying.

Does the conversion depend on the color space (e.g., sRGB vs Adobe RGB)?

No. The HEX code is always interpreted as sRGB (the standard for web content). The conversion to RGB is purely numerical—each hex pair becomes a 0–255 integer. The same integers are then used to derive other models (HSL, LAB) assuming sRGB primaries and gamma. That is the convention for CSS and most web tools.