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).