Skip to the color picker

Hex color codes explained: how #RRGGBB works

A hex color code like #1e90ff is three pairs of hexadecimal digits: the amount of red, green and blue light, each from 00 (none) to ff (full, 255). Add a fourth pair to set opacity: 80 means about 50%, ff means fully solid.

6 min read

How a hex color code works

Every color on a screen is mixed from red, green and blue light. A hex code writes the strength of each light as two characters after the # sign: red first, then green, then blue. That is the #RRGGBB pattern.

The characters are hexadecimal, a way of counting with 16 digits: 0 to 9, then a (10), b (11), c (12), d (13), e (14) and f (15). One pair covers 256 values, from 00 (0) to ff (255), exactly the range of rgb().

To turn a pair into a regular number, multiply the first digit by 16 and add the second. Below is #1e90ff, the CSS color dodgerblue, in four formats, and then worked out pair by pair.

Example: #1e90ff
FormatValue
HEX
RGB
HSL
OKLCH
PairChannelCalculationValue
1eRed1 × 16 + 1430
90Green9 × 16 + 0144
ffBlue15 × 16 + 15255

So #1e90ff is rgb(30, 144, 255): a little red, a fair amount of green and full blue, which adds up to a bright sky blue. Three pairs of 256 values give 16,777,216 possible colors.

3-digit and 4-digit hex shorthand

When both digits of every pair are the same, you can write each pair once. #ffcc00 becomes #fc0, and the browser doubles each digit back. #1e90ff has no short form, because 1e and 90 are not doubled pairs.

The short form covers only 4,096 of the 16.7 million colors. A four-digit version adds opacity the same way, so #f008 means #ff000088.

ShortFullColor
#fff#ffffffWhite
#000#000000Black
#f00#ff0000Red
#fc0#ffcc00Warm yellow
#abc#aabbccGrayish blue
#f008#ff000088Red at 53% opacity

Hex opacity: 8-digit hex with alpha

An eight-digit code adds a fourth pair for alpha, the opacity: #RRGGBBAA. 00 is fully transparent and ff is fully solid. Every current browser supports it in CSS, along with the four-digit #RGBA shorthand.

To get the pair, multiply the opacity by 255, round to a whole number and convert it to hex. 50% gives 127.5, which rounds to 128, written as 80. Here is the full table, applied to #1e90ff.

OpacityAlpha (0–255)Hex pair#1e90ff with alpha
100%255ff#1e90ffff
95%242f2#1e90fff2
90%230e6#1e90ffe6
85%217d9#1e90ffd9
80%204cc#1e90ffcc
75%191bf#1e90ffbf
70%179b3#1e90ffb3
65%166a6#1e90ffa6
60%15399#1e90ff99
55%1408c#1e90ff8c
50%12880#1e90ff80
45%11573#1e90ff73
40%10266#1e90ff66
35%8959#1e90ff59
30%774d#1e90ff4d
25%6440#1e90ff40
20%5133#1e90ff33
15%3826#1e90ff26
10%261a#1e90ff1a
5%130d#1e90ff0d
0%000#1e90ff00

CSS

.overlay {
    background: #00000080;
}

.overlay-same {
    background: rgb(0 0 0 / 50%);
}

Two catches. First, 80 is 128 out of 255, which is 50.2%, not exactly 50%: hex alpha has only 256 steps, so most round percentages are close approximations. Second, Android puts alpha first. In an Android color resource, #801e90ff means the same as #1e90ff80 in CSS.

How to read a hex code by eye

You can guess a color without converting anything. Look at the first digit of each pair, because it carries almost all the information.

CSS nameHexRGBHow to read it
tomato#ff6347255, 99, 71Red at full, some green and blue: a warm light red
gold#ffd700255, 215, 0Red and green high, no blue: yellow
chocolate#d2691e210, 105, 30Red leads, green half, blue low: orange brown
darkturquoise#00ced10, 206, 209Green and blue high, no red: cyan
dodgerblue#1e90ff30, 144, 255Blue leads, green in the middle: sky blue
mediumorchid#ba55d3186, 85, 211Red and blue high, green low: purple
teal#0080800, 128, 128Green and blue at half: dark cyan
navy#0000800, 0, 128Only blue, at half: dark blue
slategray#708090112, 128, 144Nearly equal, blue slightly ahead: bluish gray
  • The largest first digit is the dominant light. #d2691e has d in red, 6 in green and 1 in blue, so it is an orange brown.
  • Two high channels mix: red and green make yellow, green and blue make cyan, red and blue make magenta or purple.
  • Three equal pairs make a gray. #333333 is dark gray, #999999 is light gray. Nearly equal pairs, like #708090, give a muted, grayish color.
  • High digits overall mean a light color, low digits a dark one. When all three pairs are c0 or higher, the color is pale. When all three are 30 or lower, it is very dark.
  • Green looks far brighter than blue at the same number. #00ff00 has an OKLCH lightness of 0.866, #0000ff only 0.452.

Why #808080 is not middle gray

#808080 sits exactly halfway in the numbers: 128 out of 255 in every channel. It does not look halfway between black and white. Its OKLCH lightness is 0.600, so it reads as 60% of the way to white.

Hex values are already encoded with the sRGB curve, which roughly follows the eye but not exactly. #808080 gives off about 21.6% of the light of white, and perceptual models put the visual midpoint lower: OKLCH at #636363, CIELAB at #777777.

GrayWhat it isOKLCH LContrast on whiteContrast on black
#808080Numeric middle, 1280.6003.95:15.32:1
#777777CIELAB middle, L* 500.5694.48:14.69:1
#767676Lightest gray with 4.5:1 on white0.5664.54:14.62:1
#636363OKLCH middle, L 0.50.5006.01:13.50:1

This matters for text. Gray #808080 on white is 3.95:1 and fails WCAG AA for body text. #767676 is the lightest gray that passes 4.5:1, and #777777, one step lighter, already fails at 4.48:1.

Uppercase or lowercase, with or without #

Hex codes are not case sensitive. #1E90FF, #1e90ff and #1E90ff are the same color in CSS, SVG and design tools. Pick one style and keep it everywhere, so a search through your code finds every use. Lowercase is the common choice in CSS.

The # sign is part of the CSS syntax, not of the color. Figma and many design tools show the code without it, and programming languages often write it as a number with a 0x prefix, as in Flutter, where Color(0xFF1E90FF) starts with the alpha pair.

How to find the hex code of a color on screen

Use an eyedropper: a tool that reads the color under your cursor and shows its code. These are free and mostly already installed.

  • Chrome and Edge: open DevTools with F12, click any color square in the Styles panel and use the eyedropper icon to pick from the page.
  • PickShade: the color picker on the home page has an eyedropper button in Chrome and Edge that picks from anywhere on the screen.
  • Windows: install Microsoft PowerToys and press Win + Shift + C to open Color Picker.
  • macOS: open Digital Color Meter from Applications, Utilities. Switch it to sRGB, then choose View, Display Values, as Hexadecimal.
  • Figma, Photoshop and most design apps: press I for the eyedropper.
  • In a photo or screenshot: open it in the image color picker and click any pixel. The image stays on your device.

A picked value can be a few units off from the original, because screens apply color profiles and images are compressed. When you need the exact value, copy it from the design file or the CSS, not from a screenshot.

Questions and answers

What is a hex color code?

A hex color code is a six-digit code like #1e90ff that describes a color by the amount of red, green and blue light in it. Each pair of hexadecimal digits goes from 00 (0) to ff (255), so #1e90ff is rgb(30, 144, 255).

How do I add opacity to a hex color?

Add a fourth pair of digits at the end: #RRGGBBAA. Multiply the opacity by 255, round and convert to hex, so 50% is 80, 25% is 40 and 75% is bf. For example, #1e90ff80 is dodgerblue at about 50% opacity.

What is 50% opacity in hex?

50% opacity in hex is 80, as in #00000080 for half-transparent black. 80 equals 128 out of 255, which is 50.2%, because hex alpha has 256 steps and exact 50% falls between 7f and 80.

What is the difference between hex and RGB?

There is no difference in the color, only in the notation. Hex writes the red, green and blue values as base-16 pairs, rgb() writes them as decimal numbers from 0 to 255, so #ff6347 and rgb(255, 99, 71) are the same tomato red.

Are hex color codes case sensitive?

No. #FF6347, #ff6347 and #Ff6347 are the same color in CSS, HTML, SVG and design tools. Most CSS codebases use lowercase, but any style works as long as it is consistent.

What is the hex code for middle gray?

#808080 is the numeric middle, but it looks lighter than halfway, with an OKLCH lightness of 0.600. A gray that looks halfway between black and white is between #636363 (OKLCH L 0.5) and #777777 (CIELAB L* 50).

Try it in PickShade

Related guides