Hex to RGB: How to Convert Color Codes

To convert a hex color to RGB, split the six-digit code into three pairs — red, green, blue — and convert each pair from hexadecimal to a decimal number from 0 to 255. For example, #FF5733 becomes rgb(255, 87, 51). Below is how the two formats work, how to convert by hand, and when to reach for each.

Key takeaways

  • A hex code is three pairs of base-16 digits: RR GG BB.
  • Convert each pair (00–FF) to a decimal 0–255 to get RGB.
  • Hex and RGB describe the exact same color — pick by convenience.
  • Convert any color with the color converter.

What a hex color code means

A hex color is written as #RRGGBB, where each pair of characters is a channel:

  • RR — the red channel
  • GG — the green channel
  • BB — the blue channel

Each pair uses base-16 (hexadecimal) digits: 0–9 then A–F for the values 10–15. So each channel runs from 00 (0, none of that color) to FF (255, full intensity). That's why #000000 is black, #FFFFFF is white, and #FF0000 is pure red.

Converting a pair by hand

Each two-digit hex pair converts to decimal with: (first digit × 16) + second digit, where A–F count as 10–15.

  • FF → (15 × 16) + 15 = 255
  • 57 → (5 × 16) + 7 = 87
  • 33 → (3 × 16) + 3 = 51

Put them together and #FF5733 is rgb(255, 87, 51). To go the other way, convert each 0–255 value back to a two-digit hex pair.

Common colors in both formats

ColorHexRGB
Black#000000rgb(0, 0, 0)
White#FFFFFFrgb(255, 255, 255)
Red#FF0000rgb(255, 0, 0)
Green#00FF00rgb(0, 255, 0)
Blue#0000FFrgb(0, 0, 255)
Teal#10B981rgb(16, 185, 129)
Convert instantly: the free Color Converter turns any color between HEX, RGB and HSL with a live preview and copy-ready CSS values — pick a color or paste a code and read all three.

When to use hex vs. RGB

They produce identical colors, so it's about convenience. Hex is compact and the most common way to write solid colors in CSS and design tools. RGB (and its sibling rgba()) is handy when you need transparency — the alpha value — or when you want to tweak a single channel, since the numbers are readable decimals rather than hex pairs. Many developers use hex for fixed brand colors and rgba when they need see-through overlays.

Frequently asked questions

How do you convert hex to RGB?

Split the six-digit hex code into three pairs for red, green and blue, then convert each pair from hexadecimal to a decimal number from 0 to 255. For example, #FF5733 is rgb(255, 87, 51).

What does a hex color code mean?

A hex color code is a six-digit representation of a color using base-16 digits (0-9 and A-F). The first two digits are the red channel, the next two green, and the last two blue, each ranging from 00 to FF (0 to 255).

Should I use hex or RGB in CSS?

Both work identically. Hex is compact and common for solid colors. RGB (and rgba) is handy when you need transparency or want to adjust a single channel, because the values are readable decimals.

Related: Color Converter · Number Base Converter · all Developer Tools