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

DimensionHEXRGB
Color spacesRGBsRGB — identical
Information carriedIdenticalIdentical
Alpha4 or 8 digits: #2f81f7ccSlash syntax: rgb(47 129 247 / 0.8)
Compactness7 characters18 characters
Readable channel valuesNo — requires decodingYes
Relative color syntaxNot directlyrgb(from … r g b)
Design tool exportThe near-universal defaultLess common
Best used forHanding a value to a person or a toolCode 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

Other comparisons