Developer Tool

Hex to RGB Converter — HEX, RGB, RGBA & HSL

Convert any HEX color code to RGB, RGBA and HSL instantly — type a hex value or pick a color and copy the CSS-ready output.

Accepts 3-digit (#f00), 6-digit (#1B3A6B) or 8-digit (#1B3A6BCC) hex with or without alpha.
RGB value
rgb(27, 58, 107)
from #1B3A6B
RGBArgba(27, 58, 107, 1)
HSLhsl(217, 60%, 26%)
HEX#1B3A6B
27
Red (0–255)
58
Green (0–255)
107
Blue (0–255)
100%
Alpha
Tip: if your hex code has 8 digits, the last pair is the alpha channel — this converter reads it automatically and fills the RGBA opacity for you.

A hex to RGB converter takes a HEX color code like #1B3A6B and turns it into the rgb(), rgba() and hsl() values that CSS, JavaScript, and design tools use for calculations, animations, and transparency. Type a hex code above, or pick a color visually, and every format updates instantly — copy whichever one your project needs with a single click.

The usual reason to convert is a handoff: a brand guide gives you a hex palette, but the CSS you are writing needs an rgba() value for a translucent overlay or a hover state. Converting by hand is slow and error-prone, so this tool does it and lets you copy the result.

What This Hex to RGB Converter Does

This tool accepts a HEX color in all four hex lengths browsers support — 3-digit shorthand, 4-digit shorthand with alpha, 6-digit standard, or 8-digit with alpha — and immediately outputs the equivalent RGB, RGBA and HSL values, plus a live color swatch so you can visually confirm the result. It works the other direction too: adjust the color picker and watch the HEX and RGB values update together, so you're never stuck manually typing color codes back and forth between formats.

Everything runs instantly as you type or click, with no page reload and no server round-trip. The RGBA, HSL and HEX lines each have a copy button (the large RGB headline does not, so select it by hand), so you can grab the string you need and paste it straight into your stylesheet, a CSS-in-JS file, a design tool, or a canvas drawing script.

How to Use the Hex to RGB Converter

  1. Enter a HEX code. Type it into the text field with or without the leading # — 3, 6, or 8 digits are all accepted.
  2. Or pick a color visually. Click the color swatch picker to open your browser's native color wheel and choose any color by eye.
  3. Read the RGB value. The headline result shows the ready-to-use rgb(r, g, b) string for that color.
  4. Check RGBA if you need transparency. The RGBA line shows the same color with an alpha value — 1 by default, or automatically derived if your hex code included an 8-digit alpha pair.
  5. Copy what you need. Click the copy button next to RGBA, HSL or HEX to place that exact string on your clipboard.

The Formula — How Hex to RGB Conversion Actually Works

Here's the part most tutorials skip: hex is just RGB written in base-16 instead of base-10. A 6-digit hex code like #1B3A6B is really three separate two-digit hexadecimal numbers glued together — 1B, 3A, and 6B — one pair for red, one for green, one for blue. Each pair can represent any value from 00 to FF in hexadecimal, which is exactly the same range as 0 to 255 in decimal — the range every RGB channel in CSS uses.

So converting hex to RGB is nothing more than converting each of those three hex pairs into its decimal equivalent: 1B in hex equals 27, 3A equals 58, and 6B equals 107, which is the rgb(27, 58, 107) this tool produces for that swatch. The MDN hex-color reference describes the same notation, and its CSS color value page notes that a colour's actual appearance can vary from device to device because most displays are not calibrated.

That's also why this converter can run entirely in your browser with a few lines of JavaScript: parse the hex string as a base-16 integer, then use bit shifting or substring slicing to pull out each channel, and format the result as a decimal string. No lookup table, no external color library, and no network request required — the math is genuinely that simple once you see hex for what it is.

Why Hex Codes Come in 3, 4, 6 and 8 Digits

A lot of confusion around hex colors comes from not knowing which lengths are valid. CSS has four hex forms: 3 digits (#RGB), 4 digits (#RGBA), 6 digits (#RRGGBB) and 8 digits (#RRGGBBAA). This converter reads all four. The 4-digit #RGBA form is expanded like the 3-digit one, so #1B3C becomes #11BB33CC. The other three:

  • 3-digit shorthand (#f00) — a compact form where each digit is automatically doubled to build the full value. #f00 expands to #ff0000, because CSS repeats each character: f becomes ff, and 0 becomes 00. This shorthand only works for colors where both digits in each channel are identical, so it can't represent every possible color — just a convenient 4,096-color subset that happens to include pure red, green, blue, black, white, and the primary web-safe hues.
  • 6-digit standard (#1B3A6B) — the format almost everyone means when they say "hex code." Two digits per channel give the full 0–255 range per color, for 16,777,216 possible colors — the entire RGB color space.
  • 8-digit with alpha (#1B3A6BCC) — the same 6-digit color with two extra digits appended for opacity. Those final two digits work exactly like the other three pairs: a hex value from 00 (fully transparent) to FF (fully opaque) that this converter reads and turns into the decimal alpha shown in the RGBA output and the Alpha metric above.

MDN marks the hex-color type as widely available across browsers since July 2015 as a whole; see the compatibility table on its hex-color page for the 4- and 8-digit forms specifically. If you must support very old browsers, use rgba() for transparency, which is the RGBA line this tool gives you.

Why You'd Convert Hex to RGB or RGBA in the First Place

Designers and brand guidelines almost always hand off colors as hex — it's compact, it's what color pickers in Figma and Photoshop display by default, and it's the format most people recognize on sight. But once that hex code lands in real CSS, RGB and RGBA are frequently the more useful forms:

  • Transparency and overlays. Hex alone has no opacity concept in its plain 6-digit form. To fade a brand color into a semi-transparent overlay, modal backdrop, or hover state, you need rgba(r, g, b, alpha) — and you need the RGB numbers to build it.
  • CSS animations and JavaScript color interpolation. Animating between two colors — a button that shifts shade on hover, a loading bar that changes hue — is far easier to reason about and calculate in RGB or HSL than in raw hex strings, because RGB gives you three separate numeric channels you can interpolate mathematically.
  • Canvas and WebGL work. The HTML canvas API and many graphics libraries expect RGB or RGBA values, not hex, when you're drawing programmatically.
  • Dynamic theming. When a theme system needs to lighten, darken, or blend a base color at runtime, working with the individual R, G and B numbers (or HSL's hue/saturation/lightness) is much more tractable than string-manipulating a hex code.

This is the practical reason a hex to RGB converter earns a permanent spot in a front-end developer's toolkit: the handoff format and the working format are often different, and converting by hand invites transposition errors that are painfully hard to spot in a six-character string.

HSL: The Bonus Format You Often Actually Want

Alongside RGB and RGBA, this tool also converts your hex color to HSL — Hue, Saturation, Lightness. Where RGB describes a color as a mix of three light channels, HSL describes it the way a person actually thinks about color: what hue is it, how vivid, and how light or dark. That makes HSL the easiest format for programmatically generating a hover state (bump the lightness a few points) or a muted secondary color (lower the saturation) from a single brand hex value — adjustments that are awkward to do accurately in raw hex or RGB.

Converting colors by hand for your own site?

Arb Digital designs and builds websites with a defined colour palette and accessible contrast as part of the web design service, so your colours are set once and used consistently.

See Our Web Design Services All Free Tools

How to Read the Result

The default #1B3A6B gives rgb(27, 58, 107), rgba(27, 58, 107, 1), hsl(217, 60%, 26%) and alpha 100%. Other inputs, run through the same code:

InputRGBRGBAHSLAlpha
#1B3A6B (default)27, 58, 107rgba(27, 58, 107, 1)hsl(217, 60%, 26%)100%
#f00255, 0, 0rgba(255, 0, 0, 1)hsl(0, 100%, 50%)100%
#1B3A6BCC27, 58, 107rgba(27, 58, 107, 0.8)hsl(217, 60%, 26%)80%
E8A020 (no #)232, 160, 32rgba(232, 160, 32, 1)hsl(38, 81%, 52%)100%
#1b317, 187, 51 (#11BB33)rgba(17, 187, 51, 1)hsl(132, 83%, 40%)100%
#80808080128, 128, 128rgba(128, 128, 128, 0.5)hsl(0, 0%, 50%)50%
  • Alpha is rounded. The RGBA value rounds alpha to two decimals, so CC (204/255) shows as 0.8 and 80 (128/255) as 0.5.
  • HSL is rounded to whole numbers, so converting it back may differ from the original by a unit.
  • The HEX line is always 6 digits. The alpha pair is dropped from it and shown in the RGBA line and the Alpha tile.
  • The colour picker has no alpha, and it overwrites the text box with a 6-digit value.

What to Do Next

  • Need a translucent overlay: copy the RGBA line and change only the last number.
  • Need a hover state: copy the HSL line and raise or lower the lightness by a few points.
  • Going the other way: use the RGB to HEX converter.
  • Before you ship text in this colour: test it against its background in the colour contrast checker. The default navy on white passes comfortably, but gold #E8A020 on white does not.

Common Mistakes to Avoid

  • Forgetting the shorthand doubles each digit. #1b3 is not the same as #1b3300 — it expands to #11bb33, doubling each character individually.
  • Mixing up hex alpha with a percentage. An 8-digit hex alpha pair is a hex value (00–FF), not a direct percentage — 80 in hex is roughly 50% opacity, not 80%.
  • Mixing percentages and numbers in the old comma syntax. rgb(10%, 20%, 40%) is valid, but in the older comma-separated syntax you should use percentages for all three channels or numbers for all three, not a mix.
  • Assuming every hex color has a clean 3-digit shorthand. Only colors where both digits per channel match can be shortened; most real-world brand colors, like the #1B3A6B default above, cannot.
  • Copying a hex value with a stray character. A value that is not 3, 4, 6 or 8 hex digits (after an optional #) shows "Invalid HEX" with a red outline instead of a result.

Related Free Tools From Arb Digital

Need to go the other direction? Use the RGB to hex converter to turn R, G, B numbers back into a hex code. Once you have your color, build a full gradient with the CSS gradient generator, add depth with the box shadow generator, check accessibility with the color contrast checker, or explore any color visually with the color picker & converter. Browse every tool at our free online tools hub.

Frequently Asked Questions

How do I convert hex to RGB manually?

Split the 6-digit hex code into three two-digit pairs — one each for red, green and blue. Convert each pair from base-16 to base-10: for example, in #1B3A6B, 1B equals 27, 3A equals 58, and 6B equals 107, giving rgb(27, 58, 107). This tool does that conversion instantly so you don't have to do the base-16 math by hand.

What is the difference between RGB and RGBA?

RGB describes a color with three channels — red, green and blue, each 0–255 — and is always fully opaque. RGBA adds a fourth value, alpha, from 0 (fully transparent) to 1 (fully opaque), letting you control transparency. This converter shows both, defaulting alpha to 1 unless your hex code includes an 8-digit alpha pair.

Does a 3-digit hex code work the same as 6-digit?

Yes, functionally. A 3-digit shorthand like #f00 is expanded by doubling each digit — f becomes ff and 0 becomes 00 — producing the equivalent 6-digit color #ff0000. This converter accepts either length and always produces the same RGB output for equivalent colors.

What does the alpha pair in an 8-digit hex code mean?

The final two digits of an 8-digit hex color, such as CC in #1B3A6BCC, set the opacity using the same 00-to-FF hexadecimal scale as the other channels. 00 is fully transparent, FF is fully opaque, and this converter reads that pair automatically and reflects it in the Alpha metric and the RGBA output.

Why would I use RGB instead of hex in my CSS?

RGB and RGBA are easier to animate, interpolate and manipulate programmatically because each channel is a separate number rather than a packed string. They're also required whenever you need transparency in older browsers, and they're the format most canvas and JavaScript color libraries expect.

Is this hex to RGB converter free and private?

Yes — completely free, with no sign-up or usage limits. Every conversion happens locally in your browser using plain JavaScript; nothing you type is stored or sent anywhere.

What happens if I type an invalid hex code?

The result area shows "Invalid HEX" and the input is outlined in red until you correct it. Valid input is 3, 4, 6 or 8 hex digits, with or without a leading #.

This tool runs entirely client-side in your browser — no colors you enter are ever sent to a server or stored.

Turn this result into a plan

Need something more advanced? Try the free AI Website Audit and Keyword Research tools.