Skip to content
Hex Color Picker

Blog

How Hex Color Codes Work (and How to Read Them at a Glance)

By the Hex Color Picker Team. Published . 8 minute read.

A hex color code is three numbers written as six characters. The first two characters are the amount of red, the next two are green and the last two are blue. Each pair is a number in base 16, from 00 (none) to FF (full strength). So #FF0000 is full red with no green or blue, #000000 is black, and #FFFFFF is white.

Once you know that, you can read most codes at a glance and convert any of them by hand. This guide shows how, with worked examples, then covers the shorthand and eight-digit forms, how to estimate a color from its code, and the mistakes that make a code invalid. If you'd rather not do the arithmetic, the hex to RGB converter and the RGB to hex converter do it instantly.

What the code is made of

A code such as #1E90FF has two parts:

Each pair is a number between 0 and 255, written in base 16 instead of base 10. That is why two characters are enough: the largest two-digit base-16 number, FF, is 255, which is the strongest a screen channel can be.

The total number of possible codes is 16 to the sixth power, which is 16,777,216. That is the same as 256 x 256 x 256, because each of the three channels has 256 possible values. Hex and RGB describe exactly the same set of colors.

Base 16 in one minute

You count in base 10, with ten digits from 0 to 9. Base 16 needs sixteen digits, so it borrows the first six letters of the alphabet:

Hex digit0 to 9ABCDEF
Value0 to 9101112131415

In a two-digit number, the left digit counts sixteens and the right digit counts ones. So 3C is 3 x 16 + 12 = 60, and FF is 15 x 16 + 15 = 255. The letters are not case sensitive, so ff and FF mean the same thing.

Reading a code pair by pair

Take #1E90FF. Split it into three pairs and convert each:

  1. Red: 1E is 1 x 16 + 14 = 30.
  2. Green: 90 is 9 x 16 + 0 = 144.
  3. Blue: FF is 15 x 16 + 15 = 255.

The color is rgb(30, 144, 255), which CSS names dodgerblue. Blue is at full strength, green is a little over half, and red is low, so the code describes a bright blue that leans a little toward cyan.

You can often get a rough idea of a color before converting anything:

Converting RGB to hex by hand

Going the other way means turning each decimal number into two hex digits. Divide by 16: the whole-number result is the first digit, and the remainder is the second.

Take rgb(220, 20, 60), the CSS color crimson:

  1. Red: 220 divided by 16 is 13 remainder 12. Thirteen is D and twelve is C, so the pair is DC.
  2. Green: 20 divided by 16 is 1 remainder 4, so the pair is 14.
  3. Blue: 60 divided by 16 is 3 remainder 12, so the pair is 3C.

Join them and add the marker: #DC143C.

One detail catches people out. A single-digit result still needs two characters, so a channel value of 5 is 05, not 5. So rgb(5, 5, 5) is #050505. Without the leading zero the code would be the wrong length and the color would break.

Shorthand codes

When each of the three pairs is made of two identical digits, CSS lets you write just one digit from each pair. The browser repeats every digit to rebuild the full code:

ShortExpands toColor
#F00#FF0000Red
#0F0#00FF00Lime
#F80#FF8800A bright orange, rgb(255, 136, 0)
#FFF#FFFFFFWhite
#369#336699A muted blue

The shorthand only works when every pair repeats. #1E90FF can't be shortened, because 1E is two different digits. It is a convenience for typing, and nothing more: #F80 and #FF8800 are the same color.

Eight-digit codes and transparency

Add two more digits and you get an alpha channel, which controls transparency. The format is #RRGGBBAA. The alpha pair runs from 00 (fully transparent) to FF (fully opaque), the same 0 to 255 scale as the colors.

To pick an alpha value, multiply the opacity you want by 255 and convert to hex. These are the values you'll use most:

OpacityAlpha pair
100%FF
90%E6
75%BF
50%80
25%40
10%1A

So #1E90FF80 is dodgerblue at about 50% opacity. There is also a four-digit form, #RGBA, which is the shorthand for it. If you prefer decimals, rgb(30 144 255 / 50%) says the same thing in plainer terms, and it is covered in the guide to colors in CSS and HTML.

Greys and equal pairs

When all three pairs are the same, the color is a grey, because equal amounts of red, green and blue light give no hue. #000000 is black, #808080 is the middle grey, #C0C0C0 is a light grey called silver in CSS, and #FFFFFF is white. If you see a code like #333333 or #EEEEEE, you know without converting that it is a neutral grey, and the number tells you roughly how dark: 33 is 51 out of 255, quite dark, while EE is 238, very light.

A common design trick is a "tinted grey", where the three pairs are almost equal but not quite, such as #EEF1F7. It looks neutral but carries a faint blue cast, which often feels more natural next to a brand color than a pure grey.

Estimating a color from the code

With a little practice you can guess the family of a color from the code alone. Here is a quick checklist:

Try it on #2E8B57. The green pair, 8B, is clearly the largest, so it is a green. Red (2E) and blue (57) are low and fairly close, so it is not a neon green but a muted, dark one. That is seagreen. Now #F5F5DC: all three pairs are very high, with blue a little lower, so it is a very light color with a faint yellow cast. That is beige.

Case, the hash and other details

Common mistakes

  1. A missing or extra digit. The most common typo, and it produces an invalid color or, with a three-digit code, a completely different one. If a color looks wrong, count the characters.
  2. Confusing the letter O with the digit 0, or I with 1. Hex only uses 0 to 9 and A to F, so O is never valid.
  3. Reading the code left to right as one number. It is three separate numbers, not one big one. #1E90FF is not a single value of 2 million.
  4. Assuming bigger always means brighter in a way the eye sees. Equal numbers don't give equal brightness across colors. A full green looks much brighter than a full blue. The contrast guide explains how to measure it.
  5. Forgetting the zero in a small channel. #5 in a channel is 05.

Why hex is so widely used

Hex is compact, it can be pasted anywhere, it has no spaces or commas to mistype, and it round-trips exactly with RGB. That is why brand guidelines, design tools and stylesheets all default to it. It isn't the friendliest format for adjusting a color, though, and for that you may want HSL. For the bigger picture of how hex fits with the other formats, read Hex, RGB, HSL and CMYK explained.

Frequently asked questions

What does the # mean in a hex color code?

It marks the text as a hex color, so the browser knows to read the next characters as base-16 digits. It carries no color information itself.

How many colors can a hex code represent?

16,777,216, which is 16 to the power of 6, or 256 values for each of three channels.

What is the hex code for white and black?

White is #FFFFFF (or #FFF) and black is #000000 (or #000).

Can a hex code have more than 6 digits?

Yes, 8 digits, where the last two are the alpha (transparency) channel. Other lengths, apart from 3 and 4 for shorthand, are invalid.

How do I convert a hex code to a name?

CSS defines 148 color names, and the named colors section lists the ones we cover. If your code matches one exactly, the hex color picker tells you the name. Otherwise it shows the closest CSS name.

Is a hex code the same as an RGB value?

Yes. They are the same three numbers written differently, and the conversion is exact in both directions.

Try it yourself

More guides