Comparison
HEX vs RGB
This is not a question about color. Both are sRGB, both carry exactly the same information, and every hex code has an identical rgb() form.
Short answer. They are the same color in two notations, so pick by context: HEX to hand someone a value, <code>rgb()</code> when code has to read or modify the channels.
#2f81f7 and rgb(47 129 247) are the same color. The hex form is three base-16 pairs; the functional form is the same three numbers in base 10. Nothing is lost or gained converting between them, and no rendering difference exists.
So the choice is ergonomic. HEX is compact, unambiguous when copied, and the format every design tool exports — which is why it is what you paste into Slack. Its cost is that it is opaque to arithmetic: you cannot read a hex code and know it is slightly more red than another without decoding it first.
rgb() is the better form when something has to operate on the channels: modern CSS lets you write rgb(from var(--brand) r g b / 50%), and a human reading the three numbers can see what will change. Both support alpha — #2f81f7cc as a fourth pair, or the / 0.8 slash syntax — but the functional form makes it legible.
HEX vs RGB, side by side
| Dimension | HEX | RGB |
|---|---|---|
| Color space | sRGB | sRGB — identical |
| Information carried | Identical | Identical |
| Alpha | 4 or 8 digits: #2f81f7cc | Slash syntax: rgb(47 129 247 / 0.8) |
| Compactness | 7 characters | 18 characters |
| Readable channel values | No — requires decoding | Yes |
| Relative color syntax | Not directly | rgb(from … r g b) |
| Design tool export | The near-universal default | Less common |
| Best used for | Handing a value to a person or a tool | Code that reads or modifies channels |
Where this comparison is unfair
Neither is a good space to think in. Both are gamma-encoded sRGB, so averaging two of them does not give you the color between them, and neither tells you anything useful about how light or how colorful a color is. For generating or reasoning about color, convert to OKLCH; use HEX and RGB as transport.
Three-digit hex is a shorthand, not a separate format: #2af expands to #22aaff by doubling each digit, so it can only express 4,096 of the 16.7 million sRGB colors.
Frequently asked questions
Is HEX or RGB better?
Neither — they encode identical colors in sRGB. Use HEX to hand a value to a person or paste into a design tool, and rgb() when code needs to read or modify individual channels.
How do I convert HEX to RGB by hand?
Drop the #, split the six digits into three pairs, and read each pair as base 16 — multiply the first digit by 16 and add the second, where a–f are 10–15. 2f is 2 × 16 + 15 = 47.
Does HEX support transparency?
Yes. An eight-digit hex code adds a fourth pair for alpha, so #2f81f7cc is that blue at 80%. Four-digit hex is the shorthand form. Support is universal in current browsers.
Is RGB the same as sRGB?
In CSS, effectively yes — rgb() values are interpreted as sRGB unless a color space is stated. "RGB" in general means any additive red-green-blue model; sRGB is the specific one with defined primaries and a defined transfer function that the web assumes.
Try it yourself
Definitions
- sRGBsRGB is the default color space of the web: a specific set of red, green and blue primaries plus a transfer function that says how the stored numbers map to emitted light.
- Gamma correctionGamma correction is the non-linear encoding applied to color values so that the limited bits available are distributed the way human vision needs them.
- Alpha compositingAlpha compositing is combining a translucent color with what is behind it, weighted by the alpha channel.
- Color spaceA color space is a coordinate system for color: a set of axes, a defined range on each, and a rule for turning a point into a physical color.
Other comparisons
- OKLCH vs HSLBoth are cylindrical: a hue angle, a colourfulness axis and a lightness axis. Only one of them measures lightness in a way your eye agrees with.
- WCAG contrast vs APCAOne is the standard you will be measured against. The other is the better model of what your eye is doing. You need both, for different reasons.
- Lab vs OKLabSame shape: a lightness axis and two opponent axes. Forty-four years apart, and fitted to different data.
- RGB vs CMYKOne model adds light, the other removes it. That is not a detail — it changes which colors are reachable and which conversions can be trusted.
- sRGB vs Display P3P3 covers around 25% more area than sRGB. Almost all of it is in the reds, oranges and greens; there is very little extra blue.