Key takeaways
- A hex code is three pairs of base 16 digits for red, green and blue.
- Shorthand and 8-digit codes cover repeated digits and opacity.
- Use hex to share colors and HSL or OKLCH to adjust them.
Hex color codes are the most common way to write colors on the web. This guide explains how they work and how to use them confidently.
What a hex code is
A hex code is a hash sign followed by six characters, such as #1E90FF. The characters are hexadecimal digits: 0 to 9 and A to F. Together they describe how much red, green and blue light a screen should mix.
How to read one
Split the code into three pairs. The first pair is red, the second is green and the third is blue. Each pair runs from 00 (none) to FF (full, or 255). #FF0000 is pure red and #0000FF is pure blue. Equal values in all three pairs produce a gray, from #000000 to #FFFFFF.
Shorthand codes
If each pair repeats a digit, you can write three characters instead of six. #FFF means #FFFFFF, and #0AF means #00AAFF.
Adding transparency
Eight-digit hex adds a pair at the end for opacity. #1E90FF80 is the same blue at about 50 percent. Use the hex with opacity tool to calculate any level.
Hex compared with other formats
Hex is compact and universal, so it is ideal for sharing and storing a color. RGB is convenient for calculations. HSL and OKLCH are best when you need lighter, darker or softer variations. Our comparison of hex, RGB and HSL goes deeper.
Converting hex to other formats
Use the color converter for any format, or the dedicated pages for hex to RGB and hex to HSL.
Common mistakes
- Forgetting the hash sign in CSS.
- Mixing up the order of eight-digit codes. The opacity pair is last.
- Assuming a hex code will look identical in print. Screens and printers use different color systems, which we explain in RGB vs CMYK.
- Choosing a color without testing text contrast.
Where to go next
Browse the named colors, explore the swatch library or look up any code in the search box on the home page.