HEX to RGB Converter

Convert a color between HEX codes and RGB values in both directions.

Supports 6-digit and shorthand 3-digit HEX codes.

Updated August 14, 2026
Frank Zhao - Creator
CreatorFrank Zhao
Loading calculator…

Introduction / overview

The HEX to RGB Converter translates a color between the two formats you are most likely to meet in web and screen work: a hexadecimal code such as #ffa500\#\mathrm{ffa500} and an RGB triplet such as (255, 165, 0)(255,\ 165,\ 0). Pick the direction you need, enter what you have, and the tool fills in the other side instantly.

Both directions work: start from a hex code or from red, green, and blue channels, and the tool recovers the same underlying color and converts it back the other way.

This is the tool you reach for whenever you have a color in one notation and need it in the other — a web developer copying a brand hex code out of a stylesheet and into CSS, a designer turning a hex value into RGB numbers for a design tool, or a student checking how the two notations relate. In HEX to RGB mode you can also switch on shorthand hex codes like #FAB\#\mathrm{FAB}, which CSS expands to #FFAABB\#\mathrm{FFAABB}. If your project calls for more formats at once, the Color Converter shows hex, RGB, HSL, HWB, CMYK, and color names side by side from one input.

How to use / quick start

1

Choose the direction

Under Conversion direction, pick HEX to RGB (the default) when you have a code, or RGB to HEX when you have channels.

2

Enter the color

HEX to RGB: type the hex digits — the #\# is added for you. With Allow shorthand HEX notation enabled, use 3 digits such as FAB; otherwise use 6 such as FFA500. RGB to HEX: type whole numbers from 0 to 255 for R, G, and B.

3

Read the result

The other representation appears in the result box — an RGB triplet like (255, 165, 0)(255,\ 165,\ 0) in HEX to RGB mode, or a hex code like #ffa500\#\mathrm{ffa500} in RGB to HEX mode. Select the text to copy it straight into your code.

Example — hex #ffa500 becomes RGB 255, 165, 0

In HEX to RGB mode, type #ffa500\#\mathrm{ffa500}. The six digits are read in pairs — red, green, then blue:

#ffa500\#\mathrm{ffa500}  \ \Rightarrow\ ff255\mathrm{ff} \to 255a5165\mathrm{a5} \to 165000\mathrm{00} \to 0  \ \Rightarrow\ (255, 165, 0)(255,\ 165,\ 0)

The same orange is the color behind the CSS keyword orange.

Example — shorthand hex #FAB becomes RGB 255, 170, 187

In HEX to RGB mode, enable Allow shorthand HEX notation and type FAB\mathrm{FAB}. Each digit is duplicated into a full pair, then read back as channels:

#FAB\#\mathrm{FAB}  \ \Rightarrow\ #FFAABB\#\mathrm{FFAABB}  \ \Rightarrow\ (255, 170, 187)(255,\ 170,\ 187)

That is the same pink-purple you would get from the full #ffaabb\#\mathrm{ffaabb} code.

Calculation method

Both notations describe the same red, green, and blue intensities in the standard sRGB color model. A channel takes one of 256256 possible levels, from 00 (off) to 255255 (full), and that range fits exactly into two hex digits.

Hex to RGB

R=H65536R = \left\lfloor \frac{H}{65536} \right\rfloorG=Hmod65536256G = \left\lfloor \frac{H \bmod 65536}{256} \right\rfloorB=Hmod256B = H \bmod 256

A six-digit code is one 24-bit number H=R65536+G256+BH = R\cdot 65536 + G\cdot 256 + B. In practice you do not need the floor division — just read the code in pairs. For #ffa500\#\mathrm{ffa500}, the pairs are ff\mathrm{ff}, a5\mathrm{a5}, and 00\mathrm{00}, which are 255255, 165165, and 00.

RGB to hex

#=R16 G16 B16\# = \mathrm{R}_{16}\ \mathrm{G}_{16}\ \mathrm{B}_{16}with V=16h1+h0\mathrm{with}\ V = 16\,h_1 + h_0

Each 02550\text{–}255 channel becomes two hex digits using V=16h1+h0V = 16h_1 + h_0, so 255255 is ff\mathrm{ff}, 165165 is a5\mathrm{a5}, and 00 is 00\mathrm{00}. The three pairs are joined under one #\#. Because each pair is exactly 8 bits, the whole code is one 24-bit number.

Shorthand hex codes

#FAB  #FFAABB\#\mathrm{FAB}\ \Rightarrow\ \#\mathrm{FFAABB}

A 3-digit code duplicates each digit: FFF\mathrm{F} \to \mathrm{FF}, AAA\mathrm{A} \to \mathrm{AA}, BBB\mathrm{B} \to \mathrm{BB}. This is the official shorthand defined by the CSS Color Module Level 4, where hex codes take 3, 4, 6, or 8 digits and letter case does not matter. This tool accepts the 3- and 6-digit opaque forms; the 4- and 8-digit forms that add transparency are not supported here.

Variables

  • R, G, BR,\ G,\ B — red, green, and blue channels (0–255)
  • HH — the combined 24-bit value of the color
  • h1, h0h_1,\ h_0 — the two hex digits of a single channel
  • 1616 — the base of hexadecimal notation

Frequently asked questions

Does the case of hex letters matter?

No. #FFA500\#\mathrm{FFA500} and #ffa500\#\mathrm{ffa500} are the same color in CSS, and the tool accepts either. The result box simply shows lowercase for a consistent readout.

Do I need to type the # myself?

No — the #\# is shown as a fixed prefix on the input. Type only the digits, or paste a code that already includes the #\# — both work.

Why can’t I enter a 4- or 8-digit code with transparency?

The 4- and 8-digit hex forms add an alpha (transparency) channel, which is outside the scope of a hex-to-RGB conversion. This tool converts opaque colors only, so it accepts the 6-digit form and, with shorthand enabled, the 3-digit form. For transparency, combine an opaque color with a CSS opacity value instead.

Limitations

This converter works with the standard 8-bit sRGB model used on screens. Hex codes must be 6 digits, or 3 digits when Allow shorthand HEX notation is enabled, and RGB channels must be whole numbers from 00 to 255255. Codes shorter or longer than the mode expects are rejected. The 4- and 8-digit forms with alpha are not supported, and how a color actually looks on your monitor depends on your display and color profile. A hex code is just a numeric recipe for a color — the tool converts that recipe faithfully but cannot guarantee two screens show it identically.

HEX to RGB Converter - Convert Hex to RGB Color Codes