Polotno

Color converter

HEX to RGB converter

Paste a hex color code, get RGB plus copy-ready CSS rgb() and hsl() values, a live swatch, and a contrast check. Free, no signup, fully client-side.

#1DB954
RGB

Contrast: 2.59:1 on white, 8.12:1 on black. Passes WCAG AA for body text on the better background.

Common colors

Quick answer

Read each pair of hex digits as a base-16 number: #1DB954 is rgb(29, 185, 84).

Formula: #RRGGBB → R = 0xRR, G = 0xGG, B = 0xBB

The math, in one line

A hex color is three bytes written in base 16: two digits for red, two for green, two for blue, each covering 0 to 255. Converting to RGB is just reading those pairs in base 10. #1DB954 splits into 1D, B9, 54, which is 29, 185, 84.

HEX to RGB formula, step by step

Hexadecimal digits run 0 to 9 and then A to F, where A = 10, B = 11, C = 12, D = 13, E = 14 and F = 15. In a two-digit pair the first digit counts sixteens and the second counts ones:

channel = (first digit × 16) + second digit

  1. Split the code into pairs: #1DB954 gives 1D, B9 and 54.
  2. Red: 1D is 1 × 16 + 13 = 29.
  3. Green: B9 is 11 × 16 + 9 = 185.
  4. Blue: 54 is 5 × 16 + 4 = 84.

The result is rgb(29, 185, 84). Going the other way, divide each channel by 16: the quotient is the first digit and the remainder is the second. The RGB to HEX converter does that direction.

3, 4, 6 and 8 digit hex codes

  • 6 digits (#RRGGBB): the standard form, one pair per channel.
  • 3 digits (#RGB): shorthand. Double each digit, so #1B9 is #11BB99.
  • 8 digits (#RRGGBBAA): the last pair is alpha. 80 is 128, and 128 ÷ 255 is about 50% opacity, so #1DB95480 is rgb(29 185 84 / 50%).
  • 4 digits (#RGBA): shorthand for the 8-digit form, doubled the same way. #1B98 is #11BB9988.

The converter above takes the 3 and 6 digit forms. For a code with alpha, convert the first six digits and compute the alpha pair separately.

HEX to RGB in code

hex-to-rgb.ts
function hexToRgb(hex: string) {
  let h = hex.trim().replace(/^#/, "");
  // Expand shorthand: "1B9" -> "11BB99"
  if (h.length === 3) h = [...h].map((c) => c + c).join("");
  if (!/^[0-9a-f]{6}$/i.test(h)) return null;
  return {
    r: parseInt(h.slice(0, 2), 16),
    g: parseInt(h.slice(2, 4), 16),
    b: parseInt(h.slice(4, 6), 16),
  };
}

hexToRgb("#1DB954"); // { r: 29, g: 185, b: 84 }

Common values

HEXRGBColor
#FFFFFF255, 255, 255White
#0000000, 0, 0Black
#FF0000255, 0, 0Red
#00FF000, 255, 0Green
#0000FF0, 0, 255Blue
#FFFF00255, 255, 0Yellow
#00FFFF0, 255, 255Cyan
#FF00FF255, 0, 255Magenta
#808080128, 128, 128Gray
#FFA500255, 165, 0Orange
#3B82F659, 130, 246Tailwind blue-500
#1DB95429, 185, 84Spotify green

Going to print instead?

Hex and RGB both describe light on a screen. Ink needs CMYK, and the conversion is not arithmetic: it depends on paper and press. Use the HEX to CMYK converter, which runs a real ICC profile engine, rather than a formula.

Frequently asked questions

Q: How do I convert HEX to RGB?

Split the six hex digits into three pairs and read each pair as a base-16 number. #1DB954 becomes 1D = 29, B9 = 185, 54 = 84, so the RGB value is 29, 185, 84. Paste any hex code above to get the values plus copy-ready CSS.

Q: What is the formula for HEX to RGB?

For each two-digit pair, channel = (first digit × 16) + second digit, where A to F count as 10 to 15. Red uses digits 1 and 2, green digits 3 and 4, blue digits 5 and 6. For #1DB954: red is 1 × 16 + 13 = 29, green is 11 × 16 + 9 = 185, blue is 5 × 16 + 4 = 84.

Q: What is #FFFFFF in RGB?

#FFFFFF is 255, 255, 255 (white). #000000 is 0, 0, 0 (black). Each pair of hex digits covers the 0 to 255 range for one channel: FF is the maximum, 00 the minimum.

Q: What does a 3-digit hex code mean?

Shorthand. Each digit is doubled, so #1B9 expands to #11BB99. The converter accepts both forms, with or without the leading #.

Q: What does an 8-digit hex code mean?

The last pair is alpha, the opacity. #1DB95480 is the color #1DB954 at 0x80 = 128 out of 255, which is about 50% opaque: rgb(29 185 84 / 50%) in CSS. A 4-digit code such as #1B98 is the shorthand: each digit is doubled, giving #11BB9988. This converter takes 3 or 6 digits, so drop the alpha pair, convert the color, and work out the alpha separately as its decimal value divided by 255.

Q: How do I convert HEX to RGB in JavaScript?

Parse each pair with base 16: const r = parseInt(hex.slice(1, 3), 16), then slice(3, 5) for green and slice(5, 7) for blue. That assumes a 6-digit code with a leading #; expand 3-digit shorthand first by doubling each digit.

Q: Should I use hex or rgb() in CSS?

Both render identically. Hex is more compact and common in design handoffs; rgb() is easier to manipulate programmatically and required if you want to set alpha with rgb(r g b / 50%). This tool outputs both.

Q: Is HEX the same as RGB?

Yes, they describe the same sRGB color in different notation. Hex writes each channel in base 16, RGB writes it in base 10. Neither is suitable for print, where you need CMYK.

Q: How many colors can a hex code represent?

A 6-digit hex code has 256 possible values for each of three channels, so 256 × 256 × 256 = 16,777,216 colors. The 3-digit shorthand can only write 16 × 16 × 16 = 4,096 of them.

Want this in your app? Embed Polotno SDK.

TRUSTED BY

100,000+

CREATORS

300+

BUSINESSES

ExpediaUnbounceLovePopPostGridPredis.ai