RGB to HEX Converter

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

Both directions work: start from red, green, and blue channels or from a hex code, 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 pasting a brand hex code into a stylesheet, a designer pulling RGB values out of a design tool to share as a code, 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 RGB to HEX (the default) when you have channels, or HEX to RGB when you have a code.

2

Enter the color

RGB to HEX: type whole numbers from 0 to 255 for R, G, and B. 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.

3

Read the result

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

Example — RGB 255, 165, 0 becomes #ffa500

In RGB to HEX mode, type 255255, 165165, and 00. Each channel is written as two hex digits and joined:

255ff255 \to \mathrm{ff}165a5165 \to \mathrm{a5}0000 \to \mathrm{00}  \ \Rightarrow\ #ffa500\#\mathrm{ffa500}

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.

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: H=R65536+G256+BH = R\cdot 65536 + G\cdot 256 + B.

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

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.

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 an RGB-to-hex 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. RGB channels must be whole numbers from 00 to 255255, and hex codes must be 6 digits, or 3 digits when Allow shorthand HEX notation is enabled. 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.

RGB to HEX Converter - Convert RGB to Hex Color Codes