HEX encodes RGB channels in hexadecimal
A six-digit HEX color uses two hexadecimal digits for red, two for green and two for blue. Each pair runs from 00 to FF, which corresponds to decimal 0 through 255.
For example, #5B5CF0 separates into 5B red, 5C green and F0 blue. Converted to decimal, those channels become rgb(91, 92, 240).
RGB writes the channels directly
The CSS rgb() function can express the same sRGB channels directly. Modern CSS also supports optional alpha transparency and percentage forms.
Because the channel values describe the same sRGB color, switching between equivalent HEX and RGB values does not inherently alter the appearance.
When to use HEX or RGB
HEX is compact and widely used in design handoffs, tokens and simple CSS. RGB is often easier to read when you need to think directly about channel values or manipulate them programmatically.
Modern CSS supports many additional color formats such as HSL, Lab, LCH, Oklab and Oklch, so HEX versus RGB is a workflow choice rather than a quality hierarchy.
Transparency and shorthand
HEX can include alpha in four- or eight-digit forms, while rgb() can include an alpha component. Three-digit HEX is shorthand that duplicates each digit, so #F09 expands to #FF0099.
When sharing a color, include enough context to make alpha and color space clear, especially when the value is used outside simple sRGB web styling.
Worked example: same color, different notation
HEX and RGB can encode the same sRGB channel values with no visual conversion between them.
Compact base-16 notation
Decimal channel notation
First byte
Second byte
Third byte
Choose the notation that fits the workflow. Converting HEX↔RGB does not inherently change the underlying sRGB color.
Useful tools
Sources and method
- MDN — CSS color values — CSS color models and syntax, including HEX, RGB and HSL.