Home Blog Converting HEX Color Codes to RGB and Back

Converting HEX Color Codes to RGB and Back

07/07/2026

HEX and RGB are two ways of writing the same color: HEX is used in CSS and graphics editors, while RGB shows up where individual channel values are needed (programs, some APIs, printing). Let's look at how the format works and how to convert between the two.

How a HEX code is structured

A HEX code is six hexadecimal digits after a hash sign: #RRGGBB. Each pair represents one channel: R (red), G (green), B (blue). Each channel is a number from 00 to FF (0–255 in decimal).

For example, #FF5733: FF (255) is red, 57 (87) is green, 33 (51) is blue. That gives a bright orange-red color.

The HEX → RGB formula

Each pair of hexadecimal digits converts to a decimal number from 0 to 255:

R = first HEX pair → decimal number
G = second HEX pair → decimal number
B = third HEX pair → decimal number

#00FF00 (pure green) → R=0, G=255, B=0, or rgb(0, 255, 0).

The other way: RGB → HEX

Each number from 0 to 255 converts to a two-digit hexadecimal value, and the three pairs are joined after a hash sign. rgb(255, 87, 51)#FF5733.

Common values

Color HEX RGB
White #FFFFFF rgb(255, 255, 255)
Black #000000 rgb(0, 0, 0)
Red #FF0000 rgb(255, 0, 0)
Green #00FF00 rgb(0, 255, 0)
Blue #0000FF rgb(0, 0, 255)
Gray #808080 rgb(128, 128, 128)

Converting online

Doing the hexadecimal math by hand is tedious and error-prone. The color converter converts instantly between HEX, RGB, and HSL, and shows a live color preview so you can confirm the code was copied correctly. It works both ways: enter a HEX code or RGB values, and the rest fill in automatically.

← All articles