Hex to RGB Conversion: Formula and Examples

All tools: Developer Tools

Convert a hexadecimal color to RGB by splitting its red, green and blue pairs, with examples for six- and three-digit CSS colors.

Open the free tool →

Quick answer

To convert a six-digit hex color to RGB, split the digits into three pairs—red, green and blue—and convert each pair from base 16 to a number from 0 to 255. For example, #336699 becomes RGB(51, 102, 153).

Convert a six-digit hex color by hand

  1. 33 is the red channel.
  2. 66 is the green channel.
  3. 99 is the blue channel.

Remove the optional hash sign, then read the value as red-red, green-green, blue-blue pairs:

Each pair is hexadecimal, so 33 hex is 51 decimal, 66 hex is 102 decimal, and 99 hex is 153 decimal. The result is RGB(51, 102, 153). In modern CSS notation, the same color can be written as rgb(51 102 153).

Convert three-digit shorthand

In CSS, a three-digit color such as #3A7 is shorthand for #33AA77: duplicate each digit, then convert the resulting pairs. That gives red 51, green 170 and blue 119, or rgb(51 170 119).

Shorthand applies to the three color channels. Do not treat a four- or eight-digit hex value as plain RGB: the extra channel represents alpha transparency in CSS color syntax.

Use a converter when accuracy matters

Manual conversion is useful for understanding the format, but a converter avoids arithmetic mistakes when handling many colors. Paste the value into the Toolnoza Color Converter (https://toolnoza.com/tools/color-converter) and check that the result is in the format your design or code expects.

Common conversion checks

  • A valid six-digit channel pair contains only hexadecimal digits from 0–9 and A–F.
  • Every RGB channel must be between 0 and 255 in the common integer notation.
  • Hex letters can be uppercase or lowercase; they represent the same value.
  • RGB and hex can represent the same sRGB color, but a different color space or alpha channel needs its own handling.

FAQ

Q: Is hex the same as RGB? A: They are two notations for specifying red, green and blue components. A six-digit hex color stores two hexadecimal digits for each channel.

Q: What does #000000 become in RGB? A: It becomes RGB(0, 0, 0), black.

Q: What does #FFFFFF become in RGB? A: It becomes RGB(255, 255, 255), white.

Further reading

  • MDN: CSS color values (https://developer.mozilla.org/en-US/docs/Web/CSS/Guides/Colors/Color_values)
  • MDN: RGB colors (https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Values/color_value/rgb)
  • Convert a color with Toolnoza (https://toolnoza.com/tools/color-converter)