What a HEX color code actually is
A HEX color code like #267D70 is a six-digit hexadecimal number. Hexadecimal is base 16 — each digit ranges from 0 to 9 or a to f, giving 16 possible values per digit. Six hex digits gives you 16⁶ = 16,777,216 possible colors — the entire sRGB color space.
The six digits are actually three pairs:
- First pair: red channel (0–255 in decimal)
- Second pair: green channel
- Third pair: blue channel
So #267D70 means:
- Red:
26= 2×16 + 6 = 38 - Green:
7D= 7×16 + 13 = 125 - Blue:
70= 7×16 + 0 = 112
That is rgb(38, 125, 112) — a teal color.
Why it's written as pairs
Each channel is 8 bits, and 8 bits = 2 hex digits (each hex digit is 4 bits). That's the reason for the pairs. A hex code is just a compressed way of writing three 8-bit values.
The 3-digit shorthand
If each of the three pairs happens to have identical digits — for example #FFCC00 — you can shorten the code to three digits: #FC0. The browser expands it back to the six-digit form. This works because #FC0 is unambiguously #FFCC00; there's only one way to expand it.
Not every code compresses this way. #267D70 cannot be shortened because 26, 7D and 70 each have different digits.
Converting HEX to RGB
The math is a straightforward hex-to-decimal conversion. You can do it by hand for any pair:
26 (hex) → 2 × 16 + 6 = 38
7D (hex) → 7 × 16 + 13 = 125
70 (hex) → 7 × 16 + 0 = 112
Or use our HEX → RGB Converter to see the result instantly.
Converting RGB to HEX
The reverse direction is also simple — divide by 16 to get each pair's digits. Our RGB → HEX Converter does this automatically.
Alpha transparency in HEX
CSS Color Module Level 4 introduced 8-digit HEX codes with alpha — #RRGGBBAA. The last two digits represent the alpha channel: 00 = fully transparent, FF = fully opaque. For example, #267D70CC is the teal color at about 80% opacity.
8-digit HEX works in every modern browser and in current versions of all major design tools. For maximum compatibility — particularly if you support older browsers — use rgba() instead.
When HEX is the right format
- CSS and HTML — HEX is compact, familiar and works everywhere.
- Design tools — Figma, Sketch, Adobe apps all accept HEX.
- Brand guidelines — HEX values are easy to write down, share and reproduce.
- Documentation — HEX is unambiguous and compact.
When to use something else
- Complex alpha work — use
rgba()orhsla()for clearer alpha semantics. - Programmatic color manipulation — use HSL or HSLuv, which are more intuitive to reason about.
- Print work — use CMYK with an ICC profile; HEX is a screen format.
FAQ
What does a HEX color code mean?
Why do HEX codes start with a hash?
Can HEX codes have transparency?
#267D70CC) is supported in modern browsers and design tools. For older compatibility, use rgba().Is HEX the same as RGB?
#267D70 and rgb(38, 125, 112) are the same color.