Guides

What Is a Hex Color Code? (RRGGBB Explained)

Desmond Okafor··7 min read

Why does #FF0000 mean red? Not "a reddish color" — pure, maxed-out red, every time, in every browser. Once that clicks, every other hex color code on the web stops being a random string of characters and turns into something you can read at a glance.

So let's take one apart.

A hex code is three numbers wearing a disguise

A hex color code is six characters after a #, like #4F46E5. The disguise is that it looks like one value. It's actually three, glued together:

  • 4F — the red channel
  • 46 — the green channel
  • E5 — the blue channel

That's the whole format: #RRGGBB. Two hex digits per channel, three channels, red then green then blue. Every color you've ever set in CSS is just those three numbers in a trench coat.

Why base-16, and why 00 to FF

Each pair is a hexadecimal number, which counts 0–9 then A–F (A is 10, F is 15). Two hex digits run from 00 to FF — and FF is 255 in ordinary decimal. That's not a coincidence. A screen stores each channel in one byte, and one byte holds exactly 0 to 255 values. Two hex digits map onto one byte perfectly, one digit per four bits, which is the entire reason hex shows up here instead of decimal.

So FF isn't a magic word for "on" — it's just the biggest a channel goes. 00 is the smallest. Red at full is FF0000; red turned all the way down with nothing else is 000000, which is black.

It's stage lighting, not a paint palette

Here's the part that trips people up. Think of the three channels as three dimmer switches on stage lights — one red lamp, one green, one blue — all pointed at the same white wall.

  • All three dimmers off (#000000): the wall is dark. Black.
  • All three at full (#FFFFFF): every lamp blazing, the colors pile up into white.
  • Red and green full, blue off (#FFFF00): red light plus green light lands as yellow.

That last one feels wrong if your instinct comes from mixing paint, where red and green give you a muddy brown. On screen you're adding light, not subtracting it — more channels means brighter and paler, not darker. Once you hold "adding lamps" in your head, the codes predict themselves: #FF00FF is red plus blue, which is magenta; #00FFFF is green plus blue, cyan.

Reading one by eye

You don't need to convert in your head to get the gist. Glance at the three pairs and rank them:

  • The biggest pair tells you which way the color leans. In #4F46E5, blue (E5) towers over red (4F) and green (46) — so it's a blue-ish color, an indigo.
  • Pairs that are close to each other pull toward grey. #808080 is all three equal in the middle: mid-grey. #333333 is equal but low: dark grey.
  • All pairs high means light and washed-out; all low means dark.

For the exact numbers, split the pairs and convert each from base-16 to decimal — 4F is 79, 46 is 70, E5 is 229 — which gives you rgb(79, 70, 229). That's a mechanical lookup, so let a hex to RGB converter do it, or go the other way and pack decimal channels into a hex code with an RGB to hex converter.

The shorthand and the fourth pair

Two variants you'll meet. The three-digit form (#4F0) is shorthand: each digit is doubled to make the real code, so #4F0 is #44FF00. It only works when both digits of every channel already match, which is why you can't shrink #4F46E5 — its pairs aren't twins.

The eight-digit form (#4F46E5CC) tacks on a fourth pair for alpha — opacity. FF is fully opaque, 00 fully transparent, CC about 80%. Handy in modern CSS, but older setups only understand six digits, so confirm support before you rely on it.

Read in hex, edit in HSL

One honest limit: hex is a fine notation for storing and copying a color, and a miserable one for changing it. "Make this 10% lighter" has no clean move in #RRGGBB — you'd have to nudge all three pairs and re-check. That's a job for HSL, where lightness is its own dial. The full comparison of HEX, RGB, and HSL walks through which notation fits which task, and a hex to HSL converter makes the jump when you're ready to adjust rather than just record.

When you'd rather not compute anything, a visual color picker hands you the hex, RGB, and HSL of any shade at once — pick with your eyes, copy the code, and move on.

The takeaway

A hex color code is three base-16 numbers — red, green, blue, each 00 to FF — describing how bright to run three stage lamps aimed at the same wall. The biggest pair names the color's lean, equal pairs drift toward grey, and full-on everything is white because you're adding light, not paint. Read it in hex, store it in hex, and convert to HSL the moment you need to change it by hand.

Try the tools

Frequently Asked Questions

What does a hex color code mean?

A hex color code specifies an on-screen color as three light channels — red, green, and blue — each written as a two-digit hexadecimal number from 00 to FF. #4F46E5 means red = 4F, green = 46, blue = E5. Higher values mean more of that channel's light. It's the same information as an rgb() value, just written in base-16.

Why is red FF0000 and not something else?

Because hex color is additive light. The first pair is red, the second green, the third blue. FF is the maximum for a channel (255 in decimal), so FF0000 is full red with no green and no blue. Green is 00FF00 and blue is 0000FF. Mixing full red and full green (FFFF00) gives yellow — which surprises people used to mixing paint, where red and green make mud.

What's the difference between a 3-digit and 6-digit hex code?

The 3-digit form is shorthand that expands by doubling each digit: #F00 becomes #FF0000, #4F0 becomes #44FF00. It only works when both digits of every channel are identical, so it can express far fewer colors. When in doubt, use the full six-digit form — every color can be written that way.

How do I convert a hex code to RGB?

Split the six digits into three pairs and convert each pair from hexadecimal to decimal: 4F is 79, 46 is 70, E5 is 229, so #4F46E5 is rgb(79, 70, 229). A hex-to-RGB converter does this instantly, and an rgb-to-hex converter packs decimal channels back into a hex code.

What does the extra pair in an 8-digit hex code do?

An 8-digit hex code (#RRGGBBAA) adds a fourth pair for alpha — opacity. AA at FF is fully opaque, at 00 fully transparent, and 80 is roughly 50%. It's supported in modern CSS and most design tools, but older environments only understand the 6-digit form, so check support before shipping it.

DO

Desmond Okafor writes for CodeUtilityKit, where the team builds free, privacy-first developer tools that run entirely in your browser. Every guide is written and reviewed by developers who use these tools daily.