HEX to RGB Converter

Convert HEX color codes to rgb() and rgba() values, one at a time or in bulk, with the math shown step by step.

Runs in your browser
Mode

HEX color

With or without #, 3, 4, 6 or 8 digits

How it was calculated

  1. Red: 4f = 4 × 16 + 15 = 79
  2. Green: 46 = 4 × 16 + 6 = 70
  3. Blue: e5 = 14 × 16 + 5 = 229

RGB values

RGB
rgb(79, 70, 229)
RGBA
rgba(79, 70, 229, 1)
CSS4
rgb(79 70 229)Space-separated syntax
Red
79
Green
70
Blue
229
Alpha
1100% opacity
0–1 floats
0.3098, 0.2745, 0.898For shaders, Swift, Android

How HEX colors map to RGB

A HEX color is just RGB written in base 16. In #4f46e5, the first pair 4f is red, 46 is green and e5 is blue. Each pair is a two-digit hexadecimal number from 00 (0) to ff (255), so a 6-digit HEX code can express the same 16.7 million colors as rgb().

Two shorter and longer forms exist. 3-digit shorthand doubles every digit — #f60 means #ff6600. 8-digit HEX adds an alpha pair at the end: #4f46e580 is the same indigo at 128 ÷ 255 ≈ 50% opacity, and #rgba is its 4-digit shorthand. This converter accepts all four lengths, with or without the #.

You need RGB when a tool or API expects separate channel numbers — canvas code, SVG filters, design-token pipelines, or rgba() overlays in older stylesheets. The bulk mode converts whole palettes, and even swaps HEX values inside pasted CSS declarations.

How to use the HEX to RGB Converter

  1. Type or paste a HEX code such as #4f46e5, f60 or #4f46e580 — the RGB values appear as you type. You can also pick a color with the native picker.
  2. Copy rgb(), rgba(), the modern space-separated syntax, or any single channel value.
  3. Read How it was calculated to see each hex pair converted to decimal.
  4. For a whole palette, switch to Bulk, paste one color per line (or CSS custom properties), choose an output format and copy or download the result.

Example

Converting #4f46e5 by hand — multiply the first digit of each pair by 16 and add the second (a = 10, b = 11 … f = 15):

4f → 4 × 16 + 15 = 79   (red)
46 → 4 × 16 + 6  = 70   (green)
e5 → 14 × 16 + 5 = 229  (blue)

#4f46e5 = rgb(79, 70, 229)

Hex digit values

Digits 0–9 keep their value; letters continue the count: a = 10, b = 11, c = 12, d = 13, e = 14, f = 15. Case does not matter, so #FF6600 and #ff6600 are identical.

Common HEX to RGB values

  • #000000 → rgb(0, 0, 0) — black
  • #ffffff → rgb(255, 255, 255) — white
  • #808080 → rgb(128, 128, 128) — mid grey
  • #ff0000 → rgb(255, 0, 0) — red
  • #00ff00 → rgb(0, 255, 0) — lime
  • #0000ff → rgb(0, 0, 255) — blue
  • #ffa500 → rgb(255, 165, 0) — orange

Frequently Asked Questions

How do I convert HEX to RGBA with transparency?

Either use an 8-digit HEX code — the last pair is the alpha (80 ≈ 0.5, cc = 0.8, ff = 1) — or convert the 6-digit code here and type your own alpha into rgba(r, g, b, alpha). To go the other way, the RGB to HEX Converter produces 8-digit codes from an alpha slider.

Is #fff the same as #ffffff?

Yes. Three-digit HEX is shorthand where each digit is repeated, so #fff = #ffffff = rgb(255, 255, 255). Only colors whose pairs repeat (like #ff6600) have a shorthand.

Why is my 5 or 7-digit HEX code invalid?

CSS only accepts 3, 4, 6 or 8 hex digits. A 5 or 7-digit value usually means a digit was dropped or added while copying — check the original source.

Is HEX or RGB better for CSS?

They render identically. HEX is shorter and common in design tools; rgb() is easier to read and, with the modern rgb(r g b / a) syntax, adds transparency cleanly. For HSL, OKLCH and other formats at once, use the Color Converter.