What Is a Hex Code?

A hex code is a six-digit code starting with # that tells a screen which color to show: the first two digits are red, the middle two are green, and the last two are blue. #FF0000 is pure red; #FFFFFF is white.

A hex code is a six-digit code that tells a screen exactly which color to show. This guide explains how it works, with examples you can copy.

The short answer

A hex code starts with # and has six digits made from 0–9 and A–F. The digits come in three pairs: the first pair is red, the second is green, the third is blue. Each pair runs from 00 (none of that color) to FF (all of it). So #FF0000 is pure red, #00FF00 is pure green, #0000FF is pure blue, #000000 is black, and #FFFFFF is white.

Why hexadecimal?

Screens build color from light: each pixel has a red, a green, and a blue light, each with 256 brightness levels (0 to 255). Writing 255 in decimal takes three characters, but in hexadecimal — base 16 — it takes two: FF. Three channels × two digits = six digits, which is compact enough to type and read. That is the whole reason hex codes exist: they are RGB values written in a shorter notation.

Reading a hex code

Hex codeRedGreenBlueColor
#FF0000FF = 25500 = 000 = 0Pure red
#00FF0000 = 0FF = 25500 = 0Pure green (lime)
#0000FF00 = 000 = 0FF = 255Pure blue
#FF5733FF = 25557 = 8733 = 51Orange-red
#80808080 = 12880 = 12880 = 128Middle gray

When all three pairs are equal, the color is a gray: #000000 is black, #808080 is middle gray, #FFFFFF is white.

Three-digit shorthand

If each pair has two identical digits, you can write the code with three digits instead of six: #F53 means #FF5533, because each digit is doubled. Browsers accept both forms, and they mean exactly the same color.

Hex codes with transparency

Modern browsers also accept eight-digit hex codes, where the last two digits set the opacity: #FF000080 is red at 50% opacity (80 in hex is 128 out of 255). The same idea in RGB is rgba(255, 0, 0, 0.5).

How many hex colors are there?

256 × 256 × 256 = 16,777,216. That is far more than the human eye can distinguish — but every one of them has a code, and the color picker can find any of them.

Frequently asked questions

What is a hex code?

A hex code is a six-digit code, starting with #, that tells a screen which color to show. The six digits are three pairs: red, green, and blue. #FF0000 is pure red, #00FF00 is pure green, #0000FF is pure blue, #000000 is black, and #FFFFFF is white.

How many hex colors are there?

There are 16,777,216 possible hex colors — 256 × 256 × 256, because each of the red, green, and blue channels has 256 possible values (00 to FF in hexadecimal).

What is the difference between hex and RGB?

They describe the same color in different notation. Hex writes each channel as two hexadecimal digits (#FF5733); RGB writes them as decimals from 0 to 255 (rgb(255, 87, 51)). Convert between them on the hex-to-RGB and RGB-to-hex pages.

Can I use a 3-digit hex code?

Yes. A 3-digit code like #F53 is shorthand: each digit is doubled, so #F53 is the same as #FF5533.

Where do I use a hex code?

In CSS (color: #3B82F6;), in design tools like Figma, in HTML color attributes, and anywhere a color value is expected. Copy any code from the color picker on this site and paste it straight in.

Related tools

Color Picker · Hex to RGB · RGB to Hex · Color Converter · Color Names