What Is a Hex Color Code? How to Read and Write One (2026)

Six little digits carry a full color. Once you see what each pair does, you can read a hex code like a sentence and write one from scratch.

A hex color code is a six-digit hexadecimal number, like #ff5733, that names the red, green, and blue levels of a color. Read left to right: the first pair sets red (ff = 255), the middle pair sets green (57 = 87), and the last pair sets blue (33 = 51). Higher digits mean more of that light; #000000 is black and #ffffff is white.

Anatomy of #ff5733

A hex color code starts with a # sign, followed by six digits in the characters 0 to 9 and a to f. Hexadecimal is base 16, so each position can hold 16 values, and two positions make 256 values, from 00 (0) to ff (255). That 0 to 255 range is exactly the range of one RGB channel, which is why hex and RGB are two notations for the same thing.

Take #ff5733, the orange-red used in this site's examples. Split it into three pairs: ff, 57, 33. The first pair is red: ff is the maximum, 255, so the red channel is fully on. The middle pair is green: 57 in hexadecimal is 87, a low-to-mid green. The last pair is blue: 33 is 51, a dim blue. Full red plus a little green and a little blue reads as a warm orange-red, which matches the swatch.

Reading a hex code by eye

You can estimate any color without a calculator. High digits mean a lot of that light; 00 means none of it. A few you can read instantly:

  • #ff0000 is pure red: full red, zero green, zero blue.
  • #00ff00 is pure green, and #0000ff is pure blue.
  • #ffff00 is yellow: full red plus full green makes yellow light.
  • #00ffff is cyan, and #ff00ff is magenta, for the same reason.
  • #800000 is dark red: half-strength red, nothing else.
  • #008080 is teal: no red, mid green and blue.

When all three pairs are equal, you get a gray, and the value sets the brightness. #333333 is a dark gray, #808080 is a medium gray, and #cccccc is a light gray. That is why gray codes look repetitive: equal red, green, and blue is the definition of a neutral.

Shorthand: when 3 digits are enough

If each pair has two identical digits, you can write the code with three digits instead of six. Each single digit simply doubles: #ff5533 shortens to #f53. Expand it back by doubling each digit, and you can convert from there. #f53 expands to #ff5533, which is rgb(255, 85, 51): ff is 255, 55 in hexadecimal is 85, and 33 is 51.

The shorthand only works when the digits repeat. #ff5733 cannot shorten because 57 and 33 are not doubled digits. When in doubt, keep all six digits; the long form is always valid.

Alpha: the 8-digit hex

Modern CSS also accepts 8-digit hex codes, where the last two digits set the opacity from 00 (transparent) to ff (opaque). #ff573380 is our orange-red at 50 percent opacity: the trailing 80 is 128 in decimal, and 128 out of 255 is about half. #ff5733ff is fully opaque, identical to the 6-digit form. Use 8-digit hex when you want transparency without switching to rgba().

How many colors can hex make?

Each of the three channels holds 256 values, so the total number of hex colors is 256 times 256 times 256, which is 16,777,216. Compare that to the 140 named CSS colors like red, teal, and papayawhip. Named colors are a convenience; hex covers every color a standard screen can show. That is why design systems store their palettes as hex tokens, not names.

Case and the hash: formatting rules

Hex codes are case-insensitive, so #ff5733, #FF5733, and #Ff5733 are identical. Lowercase is the web convention and the safer default, since most linters and design tokens use it. The leading # is required in CSS, but some contexts drop it: Figma's color picker, Tailwind's arbitrary values, and many APIs expect the six digits alone, so ff5733 without the hash. When copying a code from one tool to another, check whether the destination wants the hash or not; a pasted # in a field that expects bare digits is a common source of "invalid color" errors.

Where hex codes live

Hex is the default color notation across the web: CSS stylesheets, SVG graphics, HTML canvas (the fillStyle property), and design tools like Figma and Photoshop all accept it. It is compact, copy-paste friendly, and every developer recognizes it. Reach for RGB when you need the alpha channel in older code or computed values, and HSL when you are tweaking palettes by feel. To go between them, the free color converter translates any format instantly, and our RGB to hex guide walks through the conversion math.

Frequently asked questions

How many digits does a hex color code have?

Six digits, like #ff5733. There is also a 3-digit shorthand (#f53) that works when each pair of digits repeats, and an 8-digit form (#ff573380) that adds an alpha channel for transparency.

What do the six digits in a hex code mean?

The first two digits set the red level (00 to ff, or 0 to 255), the middle two set green, and the last two set blue. In #ff5733, red is at maximum (ff = 255), green is low (57 = 87), and blue is low (33 = 51), which reads as orange-red.

What are the hex codes for black and white?

Black is #000000 (all channels at zero) and white is #ffffff (all channels at maximum, ff = 255). Medium gray is #808080.

How do I shorten a hex code?

If each pair of digits repeats, write one digit per channel: #ff5533 becomes #f53. Each digit doubles when you expand it back. Codes like #ff5733, where the pairs do not repeat, cannot be shortened.

Why does my hex code have 8 digits?

The extra two digits are the alpha channel, which sets opacity from 00 (fully transparent) to ff (fully opaque). #ff573380 is the color at 50 percent opacity. It is the hex equivalent of rgba() transparency.

Skip the hand math. The free color converter translates HEX, RGB, and HSL instantly, with a live preview, click-to-copy values, and auto-generated tints and shades.

Try the free color converter