Guide
How Do Hex Color Codes Work?
Six digits, three bytes, three channels of light — and how to read one at a glance.
Three numbers wearing a disguise
A hex color code is not really a color. It is three ordinary numbers, each from 0 to 255, written in hex and stuck together.
#1A73E8 ┌─┴─┴─ blue E8 = 232 │ └── green 73 = 115 └─── red 1A = 26 rgb(26, 115, 232)
Each pair says how strongly one channel of light is emitted: 00 is off,
FF is full. Always red, then green, then blue.
Where 16.7 million comes from
256 levels per channel, three channels: 256 × 256 × 256 = 16,777,216. That is the "16.7 million colors" on every monitor specification, and the same fact as "24-bit color" — three bytes of eight bits each.
It also explains a limit worth knowing: a gradient across the full range has only 256 steps per
channel, which is why wide, subtle gradients band visibly on cheaper panels. There is no hex code
between #808080 and #818181.
| Digits | Bits | Channels | Colors |
|---|---|---|---|
| 3 | 12 | 4 bits each | 4,096 |
| 6 | 24 | 8 bits each | 16,777,216 |
| 8 | 32 | 8 bits plus alpha | 16.7M × 256 opacity levels |
Screens mix light, not paint
This is the part that surprises people who learned color with paint. A screen adds light, so the rules are inverted.
| Mix | Hex | Result | With paint you would expect |
|---|---|---|---|
| Red + green | #FFFF00 | Yellow | Brown |
| Green + blue | #00FFFF | Cyan | Dark blue-green |
| Red + blue | #FF00FF | Magenta | Purple |
| All three | #FFFFFF | White | Muddy brown |
| None | #000000 | Black | White paper |
All channels at maximum gives white because all the light is on. All at zero gives black because the screen emits nothing.
Reading a color without converting it
Four rules cover almost every code you will meet.
- Three equal pairs means grey.
#808080,#CCCCCC,#222222— no color at all, only brightness. - The largest pair names the family. Highest red leans warm, highest blue leans cool.
- All pairs high means pale; all low means dark.
#FFDDDDis pale pink,#330000is very dark red. - A pair at 00 saturates.
#FF0000is pure red precisely because the other two contribute nothing.
Within a pair, the first digit is worth sixteen times the second. C-something is roughly three quarters, 8-something is roughly half, 2-something is low. You can estimate any channel from its first digit alone.
Shorthand
A three-digit code expands by doubling each digit. #1A9 becomes
#11AA99.
| Shorthand | Expands to | Note |
|---|---|---|
| #FFF | #FFFFFF | White |
| #000 | #000000 | Black |
| #F00 | #FF0000 | Pure red |
| #1A9 | #11AA99 | Each digit doubled |
| #369 | #336699 | A classic web color |
Shorthand can only express colors where both digits of every channel match, which is 4,096 of the
16.7 million. #1A73E8 has no shorthand form.
The eighth and ninth digits: alpha
Two extra digits set opacity. 00 is invisible, FF is solid.
| Suffix | Opacity | Equivalent |
|---|---|---|
| FF | 100% | rgba(…, 1) |
| CC | 80% | rgba(…, 0.8) |
| 80 | 50% | rgba(…, 0.5) |
| 40 | 25% | rgba(…, 0.25) |
| 00 | 0% | Fully transparent |
Every current browser supports this, and it is more compact than rgba() for the same
result.
Why hex rather than plain numbers
CSS accepts rgb(26, 115, 232) and it means exactly the same thing. Hex persists
because six characters is shorter than sixteen, the channel split is visible without punctuation, and
every design tool, brand guide and color picker already speaks it.
Where hex is genuinely worse is editing. Making a color ten percent darker means recomputing three channels. That is what HSL is for — design in HSL where one number moves, then ship hex.
Contrast is not brightness
A color that looks bright can still be unreadable. Pure yellow on white scores 1.07:1 — essentially invisible — despite appearing vivid. Pure blue on white scores 8.6:1 and reads comfortably.
WCAG asks for at least 4.5:1 for body text and 3:1 for large text. The hex color tool reports the ratio for any color you enter, and it is worth checking rather than trusting your eye.
Frequently asked questions
How does a hex color code work?
It is three pairs of hex digits, one per color channel. Each pair is a number from 00 to FF, meaning 0 to 255, saying how strongly red, green or blue is emitted.
What does #FFFFFF mean?
White. All three channels are at maximum, so the screen emits full red, green and blue light.
Why do red and green make yellow?
Screens add light rather than mixing pigment. Red and green light together are perceived as yellow.
What is the difference between #FFF and #FFFFFF?
Nothing. The three-digit form doubles each digit, so #FFF expands to #FFFFFF.
How many colors can a hex code represent?
16,777,216 with six digits, which is 256 levels for each of three channels. That is what 24-bit color means.
What do the last two digits of an 8-digit code do?
They set opacity. 00 is fully transparent, 80 is roughly half, FF is fully opaque.