What Is a Hex Color Code?

A hex color code is a six-character (plus an optional two for alpha) representation of a color using the hexadecimal numbering system. It always starts with a # symbol followed by six characters from 0-9 and A-F.

The six characters are split into three pairs: RR for red, GG for green, and BB for blue. Each pair represents a value from 0 to 255 โ€” exactly matching RGB channels.

For example, #FF0000 means full red (255), no green (0), and no blue (0) โ€” pure red.

๐Ÿ’ก Quick fact: Hex codes are case-insensitive. #FF0000 and #ff0000 are identical. Most designers use uppercase for readability.

The Hex to RGB Formula

Converting hex to RGB is straightforward once you know how base-16 works. Here's the step-by-step formula:

  1. Take the six-digit hex code and remove the #
  2. Split it into three pairs: first two = red, middle two = green, last two = blue
  3. For each pair, convert the hexadecimal value to a decimal number from 0-255

The hex-to-decimal conversion works like this: each position represents 16 raised to a power. The left character is the "16s place" (161) and the right character is the "1s place" (160).

For pair FF: F (15) ร— 16 + F (15) ร— 1 = 240 + 15 = 255

For pair 80: 8 ร— 16 + 0 ร— 1 = 128 + 0 = 128

Example 1: Convert #2563EB to RGB

Let's walk through a real example โ€” the indigo blue used in many modern designs.

ComponentHex PairCalculationDecimal Value
Red252 ร— 16 + 5 = 3737
Green636 ร— 16 + 3 = 9999
BlueEB14 ร— 16 + 11 = 235235

Result: rgb(37, 99, 235) โ€” which is Tailwind's blue-600.

Example 2: Convert #10B981 to RGB

An emerald green, common in success states and fintech designs.

ComponentHex PairCalculationDecimal Value
Red101 ร— 16 + 0 = 1616
GreenB911 ร— 16 + 9 = 185185
Blue818 ร— 16 + 1 = 129129

Result: rgb(16, 185, 129) โ€” the famous emerald-500.

What About 3-Digit Hex Codes?

You'll sometimes see shorthand hex codes like #F00 for red or #0AF for blue. These are valid in CSS and work by doubling each character.

#F00 โ†’ #FF0000 โ†’ rgb(255, 0, 0)

#0AF โ†’ #00AAFF โ†’ rgb(0, 170, 255)

Shorthand hex only works when both characters in each pair are identical. It's mainly used for saving bytes in CSS.

8-Digit Hex: Adding Transparency

Modern CSS supports 8-digit hex codes where the last two digits represent the alpha (transparency) channel. The same conversion applies:

#FF000080 โ†’ red: FF (255), green: 00 (0), blue: 00 (0), alpha: 80 (128/255 โ‰ˆ 50% opacity)

The alpha value 00 means fully transparent, and FF means fully opaque. This is equivalent to rgba(255, 0, 0, 0.5).

โš ๏ธ Browser support: 8-digit hex codes work in all modern browsers (Chrome 62+, Firefox 52+, Safari 10+). For older browser support, use rgba() instead.

Fastest Way to Convert Hex to RGB

Doing the math by hand is fine for understanding, but in practice you'll want a faster method. Here are three options:

  1. Online converter tool: Use our Color Converter โ€” paste your hex code and instantly get RGB, HSL, HSV, and CMYK values.
  2. Browser DevTools: In Chrome DevTools, click any color swatch in the Styles panel to toggle between hex, rgb, and hsl formats.
  3. Design software: Figma, Sketch, and Photoshop all show hex and RGB side by side in the color picker.

Common Mistakes to Avoid

Next Steps

Now that you understand hex to RGB conversion, you might want to explore other color models. Head over to our Color Converter to try converting between 7 different color formats instantly.