Updated 16 November 2026 · Written by the Digital Calculators team
Key takeaways
- A hex color code is #RRGGBB: two hexadecimal digits each for red, green and blue, from 00 (none) to ff (full).
- Six digits give 256 × 256 × 256 = 16,777,216 colors.
#000000is black,#ffffffis white,#ff0000is red,#00ff00is lime and#0000ffis blue.- To convert hex to RGB, turn each pair into a number: first digit × 16 + second digit.
- For readable text, WCAG asks for a contrast ratio of at least 4.5:1 (3:1 for large text).
Hex color codes are the six-character codes, such as #ff0000 for red, used to describe colors on websites, in design tools and in apps. The code is simply three numbers written in hexadecimal: how much red, how much green and how much blue to mix, each from 00 to ff. The W3C’s CSS Color specification defines the format, and with six digits it can describe 16,777,216 different colors.
This guide explains how to read a hex code, gives a chart of common color codes with their RGB and HSL values, shows how to convert hex to RGB by hand, and covers the 3-digit shorthand, transparency and how to check that text is readable against its background. The color picker below converts any color between HEX, RGB, HSL and CMYK.

How hex color codes work
Screens make every color by mixing red, green and blue light. A hex code says how much of each to use. In the 6-digit form described by the W3C:
- The first pair of digits is the red component.
- The second pair is green.
- The last pair is blue.
Each pair is a hexadecimal number from 00 (0, none of that color) to ff (255, the maximum). So #ff0000 is full red with no green or blue, and the W3C’s own example, #00ff00, is the same color as rgb(0 255 0), a lime green.
Hexadecimal is base 16. It uses the digits 0 to 9 and then the letters a to f for 10 to 15:
| Hex digit | Value |
|---|---|
| 0 | 0 |
| 1 | 1 |
| 2 | 2 |
| 3 | 3 |
| 4 | 4 |
| 5 | 5 |
| 6 | 6 |
| 7 | 7 |
| 8 | 8 |
| 9 | 9 |
| a | 10 |
| b | 11 |
| c | 12 |
| d | 13 |
| e | 14 |
| f | 15 |
Hex codes are not case-sensitive in practice: #FF0000 and #ff0000 are the same red.
Hex color codes chart
The W3C notes that 16 of the named colors in CSS come from the original VGA palette. Here they are with their hex, RGB and HSL values:
| Color name | Hex code | RGB | HSL |
|---|---|---|---|
| black | #000000 | rgb(0, 0, 0) | hsl(0, 0%, 0%) |
| silver | #c0c0c0 | rgb(192, 192, 192) | hsl(0, 0%, 75%) |
| gray | #808080 | rgb(128, 128, 128) | hsl(0, 0%, 50%) |
| white | #ffffff | rgb(255, 255, 255) | hsl(0, 0%, 100%) |
| maroon | #800000 | rgb(128, 0, 0) | hsl(0, 100%, 25%) |
| red | #ff0000 | rgb(255, 0, 0) | hsl(0, 100%, 50%) |
| purple | #800080 | rgb(128, 0, 128) | hsl(300, 100%, 25%) |
| fuchsia | #ff00ff | rgb(255, 0, 255) | hsl(300, 100%, 50%) |
| green | #008000 | rgb(0, 128, 0) | hsl(120, 100%, 25%) |
| lime | #00ff00 | rgb(0, 255, 0) | hsl(120, 100%, 50%) |
| olive | #808000 | rgb(128, 128, 0) | hsl(60, 100%, 25%) |
| yellow | #ffff00 | rgb(255, 255, 0) | hsl(60, 100%, 50%) |
| navy | #000080 | rgb(0, 0, 128) | hsl(240, 100%, 25%) |
| blue | #0000ff | rgb(0, 0, 255) | hsl(240, 100%, 50%) |
| teal | #008080 | rgb(0, 128, 128) | hsl(180, 100%, 25%) |
| aqua | #00ffff | rgb(0, 255, 255) | hsl(180, 100%, 50%) |
A few surprises: the color named green is the darker #008000, while full green, #00ff00, is called lime. Aqua and cyan are the same color, as are fuchsia and magenta.
More popular named colors
| Color name | Hex code | RGB | HSL |
|---|---|---|---|
| orange | #ffa500 | rgb(255, 165, 0) | hsl(39, 100%, 50%) |
| pink | #ffc0cb | rgb(255, 192, 203) | hsl(350, 100%, 88%) |
| gold | #ffd700 | rgb(255, 215, 0) | hsl(51, 100%, 50%) |
| brown | #a52a2a | rgb(165, 42, 42) | hsl(0, 59%, 41%) |
| coral | #ff7f50 | rgb(255, 127, 80) | hsl(16, 100%, 66%) |
| tomato | #ff6347 | rgb(255, 99, 71) | hsl(9, 100%, 64%) |
| skyblue | #87ceeb | rgb(135, 206, 235) | hsl(197, 71%, 73%) |
| rebeccapurple | #663399 | rgb(102, 51, 153) | hsl(270, 50%, 40%) |
Shades of gray
When all three pairs are equal, the color is a gray. The higher the number, the lighter the gray:
| Shade | Hex code | RGB | HSL |
|---|---|---|---|
| gray 0 | #000000 | rgb(0, 0, 0) | hsl(0, 0%, 0%) |
| gray 20 | #333333 | rgb(51, 51, 51) | hsl(0, 0%, 20%) |
| gray 40 | #666666 | rgb(102, 102, 102) | hsl(0, 0%, 40%) |
| gray 60 | #999999 | rgb(153, 153, 153) | hsl(0, 0%, 60%) |
| gray 80 | #cccccc | rgb(204, 204, 204) | hsl(0, 0%, 80%) |
| gray 100 | #ffffff | rgb(255, 255, 255) | hsl(0, 0%, 100%) |
Prefer a full page? Open the Color Picker.
How to convert hex to RGB
Split the code into three pairs and convert each pair: first digit × 16 + second digit.
Worked example: #3b5bdb
- Red:
3b= 3 × 16 + 11 = 59 - Green:
5b= 5 × 16 + 11 = 91 - Blue:
db= 13 × 16 + 11 = 219
So #3b5bdb is rgb(59, 91, 219), a medium blue. In HSL it is hsl(228, 69%, 55%).
RGB to hex
Go the other way by dividing each number by 16. For 219: 219 ÷ 16 = 13 remainder 11, and 13 is d, 11 is b, so 219 is db. Numbers below 16 need a leading zero: 10 is 0a, not a.
These pairs are worth knowing by heart:
| Hex pair | Decimal (0 to 255) | Percent of full |
|---|---|---|
00 | 0 | 0 |
33 | 51 | 20 |
66 | 102 | 40 |
80 | 128 | 50 |
99 | 153 | 60 |
cc | 204 | 80 |
ff | 255 | 100 |
For other bases, the hex calculator converts and adds hexadecimal numbers, and the binary translator handles binary.
Shorthand: 3-digit hex codes
CSS also allows a 3-digit form. Each digit is doubled to make the 6-digit code:
| 3-digit | Means |
|---|---|
#f00 | #ff0000 |
#0af | #00aaff |
#333 | #333333 |
#fc3 | #ffcc33 |
The shorthand only works when both digits of every pair are the same, so #3b5bdb has no short form. The W3C points out that the 3-digit syntax can express only 4,096 colors, against approximately 17 million for six digits.
Transparency: 8-digit hex codes
An 8-digit hex code adds a fourth pair for alpha, which is opacity. According to the W3C, 00 is fully transparent and ff is fully opaque. Here is our example blue at different opacities:
| Opacity | Alpha pair | 8-digit code |
|---|---|---|
| 100 | ff | #3b5bdbff |
| 75 | bf | #3b5bdbbf |
| 50 | 80 | #3b5bdb80 |
| 25 | 40 | #3b5bdb40 |
| 0 | 00 | #3b5bdb00 |
To find the alpha pair for any percentage, multiply by 255, round, and convert to hex: 50% is 127.5, rounded to 128, which is 80. There is also a 4-digit shorthand that expands the same way as the 3-digit one.
Hex vs RGB vs HSL
The same color can be written several ways. For our example:
- Hex:
#3b5bdb, compact and easy to copy. - RGB: rgb(59, 91, 219), the same three numbers in decimal.
- HSL: hsl(228, 69%, 55%), which describes hue (the angle on the color wheel), saturation and lightness.
Hex and RGB are the same information in different number bases. HSL is easier for adjusting a color: keep the hue and change the lightness to get tints and shades of the same color.
Complementary colors
The complement of a color sits opposite it on the color wheel. In RGB you get it by subtracting each value from 255: the complement of #3b5bdb is #c4a424, and the complement of red (#ff0000) is aqua (#00ffff). The color palette generator builds complementary and other matching schemes, and the random color generator gives fresh ideas.
Tints and shades of one color
To build a set of matching colors, keep the hue and saturation of a color and change only its lightness. Here is our example blue, hsl(228, 69%, 55%), from dark to light:
| Shade | Hex code | RGB | HSL |
|---|---|---|---|
| lightness 15% | #0c1641 | rgb(12, 22, 65) | hsl(229, 69%, 15%) |
| lightness 30% | #182d81 | rgb(24, 45, 129) | hsl(228, 69%, 30%) |
| lightness 45% | #2443c2 | rgb(36, 67, 194) | hsl(228, 69%, 45%) |
| lightness 55% | #3d5ddb | rgb(61, 93, 219) | hsl(228, 69%, 55%) |
| lightness 70% | #7e93e7 | rgb(126, 147, 231) | hsl(228, 69%, 70%) |
| lightness 85% | #bec9f3 | rgb(190, 201, 243) | hsl(228, 69%, 85%) |
| lightness 95% | #e9edfb | rgb(233, 237, 251) | hsl(227, 69%, 95%) |
Darker versions (shades) work well for text and borders, and lighter versions (tints) for backgrounds and highlights. Because they share a hue, they look like one family. Rounding to whole RGB values can move the HSL figures by a point or so, which is normal.
Using hex codes in practice
- On websites: in CSS, write the code with a hash sign, for example
color: #3b5bdb;orbackground: #ffffff;. - In design and office apps: most color dialogs have a hex box. Type the six digits, usually without the hash, to match a color exactly.
- For brand colors: write down the exact hex codes once and reuse them, so the same blue looks identical on every page and slide.
- Finding a color you see: pick it with the color picker above, or use an eyedropper tool in your design app, then copy the hex code.
- Print is different: screens mix light (RGB), while printers mix ink (CMYK). The color picker shows a CMYK estimate, but always check printed colors with a proof.
Checking contrast for readable text
Choosing colors is not only about looks: text must be readable. The W3C’s Web Content Accessibility Guidelines (WCAG) measure this with a contrast ratio between the text color and the background, from 1:1 (no contrast) to 21:1 (black on white). At level AA, WCAG asks for at least:
- 4.5:1 for normal text
- 3:1 for large text
| Text on background | Contrast ratio | Level AA |
|---|---|---|
#000000 on #ffffff | 21.00:1 | passes for all text |
#ffffff on #0000ff | 8.59:1 | passes for all text |
#ffffff on #808080 | 3.95:1 | large text only |
#ffffff on #ff0000 | 4.00:1 | large text only |
#000000 on #ffff00 | 19.56:1 | passes for all text |
#ffffff on #ffff00 | 1.07:1 | fails |
#ffffff on #3b5bdb | 5.67:1 | passes for all text |
Notice that white on pure red and white on mid-gray both fall short for normal text, and white on yellow fails badly, while black on yellow is very clear. The color picker above shows the contrast of any color against black and white.
Frequently asked questions
What is a hex color code?
A code such as #ff0000 that gives the amount of red, green and blue in a color as three two-digit hexadecimal numbers.
What is the hex code for black and white?
Black is #000000 and white is #ffffff.
How do I convert hex to RGB?
Split the code into three pairs and convert each from hexadecimal: first digit times 16 plus the second digit. #3b5bdb is rgb(59, 91, 219).
How many hex colors are there?
16,777,216 in the 6-digit form: 256 values each for red, green and blue.
What does a 3-digit hex code mean?
Each digit is doubled, so #f00 is the same as #ff0000.
What is an 8-digit hex code?
A 6-digit color plus two digits for alpha (opacity), where 00 is fully transparent and ff is fully opaque.
Are hex color codes case-sensitive?
No. #FF0000 and #ff0000 are the same color.
How do I make a color lighter or darker?
Convert it to HSL, keep the hue and saturation, and raise or lower the lightness, then convert back to hex.
What is the hex code for red, green and blue?
Red is #ff0000 and blue is #0000ff. Full green is #00ff00, which CSS names lime; the CSS color named green is #008000.
Related calculators
Sources
- CSS Color Module Level 4, World Wide Web Consortium (W3C). Hex notation with 3, 4, 6 and 8 digits, the alpha pair, the 4,096 shorthand colors, and the named color values.
- Understanding Success Criterion 1.4.3: Contrast (Minimum), World Wide Web Consortium (W3C), WCAG 2.2. The contrast ratio formula and the 4.5:1 and 3:1 levels.