Understanding Hex Color Codes: The Complete Guide
If you have ever looked at a CSS file, a design tool, or a brand style guide, you have seen hex color codes: six-character strings like #3B82F6 or #FF5733 that somehow encode every color a screen can display. They look like a random sequence of letters and numbers, but there is a precise system behind them โ and once you understand it, you can read any hex code at a glance.
This guide covers everything from the basic structure of a hex code to shorthand notation, alpha transparency, and practical conversion techniques.
What Does "Hex" Mean?
The word "hex" is short for hexadecimal โ a numbering system that uses base 16 instead of the base 10 we use in everyday life. In base 10, digits run from 0 to 9. In base 16, digits run from 0 to 9 and then continue with the letters A through F, giving sixteen possible values per digit.
| Hexadecimal | Decimal |
|---|---|
| 0 | 0 |
| 9 | 9 |
| A | 10 |
| B | 11 |
| C | 12 |
| D | 13 |
| E | 14 |
| F | 15 |
| 10 | 16 |
| FF | 255 |
Why base 16? Because it maps cleanly onto computer memory. A single byte of data โ 8 binary bits โ can hold values from 0 to 255. In hexadecimal, that same range fits in exactly two digits: 00 to FF. This compactness is the reason hex became the standard for specifying colors in web and design contexts.
The Structure of a Hex Color Code
A standard hex color code has this structure:
# R R G G B B
The hash symbol (#) is a prefix that signals "this is a color." After it come three pairs of hexadecimal digits โ one pair each for the Red, Green, and Blue channels of the RGB color model. Each pair encodes a value from 0 (00) to 255 (FF), controlling the intensity of that channel.
For example, take #3B82F6 โ a vivid medium blue:
| Part | Value | Decimal | Meaning |
|---|---|---|---|
3B |
Red | 59 | Low red โ not much warmth |
82 |
Green | 130 | Moderate green |
F6 |
Blue | 246 | Very high blue โ dominant channel |
The high blue channel is what makes this color appear blue. The moderate green pushes it slightly toward cyan rather than pure navy. The low red keeps it cool.
Compare that to #FF5733, a coral red:
| Part | Value | Decimal | Meaning |
|---|---|---|---|
FF |
Red | 255 | Maximum red |
57 |
Green | 87 | Some green โ adds the orange quality |
33 |
Blue | 51 | Low blue โ warm |
The maximum red with moderate green produces orange-red. Low blue keeps the tone warm.
How to Read a Hex Code at a Glance
You do not need to convert to decimal to get a quick read on a hex color. A few rules of thumb:
00 = zero intensity (none of this channel)
FF = full intensity (maximum of this channel)
80 โ half intensity (128 out of 255)
This lets you decode hex codes roughly at a glance:
- #FF0000 โ full red, no green, no blue โ pure red
- #00FF00 โ no red, full green, no blue โ pure green
- #0000FF โ no red, no green, full blue โ pure blue
- #FFFF00 โ full red and green, no blue โ yellow (red + green = yellow in light)
- #FF00FF โ full red and blue, no green โ magenta
- #00FFFF โ full green and blue, no red โ cyan
- #FFFFFF โ all channels at maximum โ white
- #000000 โ all channels at zero โ black
- #808080 โ all channels at half โ medium gray
When the first two digits are high and the others are lower, the color tends toward red. High middle two digits push toward green. High last two digits push toward blue or purple.
Spotting Light vs Dark
If all three pairs have high hexadecimal values (C, D, E, F), the color will be light. If all three are low (0, 1, 2, 3), it will be dark. Equal values across all three channels always produce a neutral gray (or black or white at the extremes).
- #F0E6D3 โ all values high โ light warm beige
- #1A1A2E โ all values low โ very dark navy
- #A0A0A0 โ equal mid values โ medium gray
Shorthand Hex Notation
CSS allows a three-character shorthand when each pair of hex digits is a repeated character. For example, #AABBCC can be written as #ABC. Each digit in the shorthand is simply doubled to produce the full six-character version.
| Shorthand | Full Equivalent |
|---|---|
#F00 |
#FF0000 (pure red) |
#0F0 |
#00FF00 (pure green) |
#00F |
#0000FF (pure blue) |
#FFF |
#FFFFFF (white) |
#000 |
#000000 (black) |
#369 |
#336699 (steel blue) |
This shorthand only works when each pair is a repeated character. #3B82F6 cannot be shortened because 3B, 82, and F6 are not repeated pairs. But #336699 can be shortened to #369.
When to Use Shorthand
Shorthand hex is a valid CSS feature and will render identically to the full version. Use it freely when the code supports it. However, many design tools and brand style guides use the full six-character format for clarity and consistency โ it is immediately obvious what each channel value is without any mental expansion.
Hex with Alpha: Eight-Character Hex Codes
The standard six-character hex code does not include transparency information. To add an alpha channel (opacity), CSS supports an eight-character hex format where the last two characters specify transparency.
The alpha channel follows the same 0โ255 range, encoded as a hex pair:
| Alpha Hex | Alpha Decimal | Opacity |
|---|---|---|
FF |
255 | 100% (fully opaque) |
CC |
204 | 80% |
99 |
153 | 60% |
80 |
128 | ~50% |
66 |
102 | 40% |
33 |
51 | 20% |
00 |
0 | 0% (fully transparent) |
For example, to use the blue #3B82F6 at 50% opacity: #3B82F680.
To use a dark overlay #000000 at 70% opacity: #000000B3.
Four-Character Shorthand with Alpha
Just as #RGB is shorthand for #RRGGBB, there is a #RGBA shorthand for #RRGGBBAA. Each digit is doubled:
#F00F=#FF0000FF(pure red, fully opaque)#0008=#00000088(black at ~53% opacity)#FFF0=#FFFFFF00(fully transparent white)
Alternatives to Hex Alpha
Before eight-character hex was widely supported, the standard way to add transparency was rgba():
/* These are equivalent */
background-color: #3B82F680;
background-color: rgba(59, 130, 246, 0.5);
Both are now well-supported in modern browsers. The rgba() form is often more readable because the opacity is expressed as a human-readable decimal (0 to 1) rather than a hex pair that requires mental conversion.
Converting Hex to Other Formats
Hex codes describe the same RGB colors as rgb() notation โ they are just a more compact representation. Converting between them is straightforward.
Hex to RGB
For each pair of hex digits, convert from hexadecimal to decimal:
- #FF5733 โ Red:
FF= 255, Green:57= 87, Blue:33= 51 - CSS:
rgb(255, 87, 51)
Hex to HSL
This conversion is more involved. HSL (Hue, Saturation, Lightness) is a perceptually intuitive format where hue is expressed as a degree on the color wheel and saturation and lightness as percentages. The Color Converter handles this instantly โ enter any hex code and it outputs the RGB, HSL, CMYK, and OKLCH equivalents simultaneously.
Hex to OKLCH
OKLCH is the most modern CSS color format, designed to be perceptually uniform. It is excellent for programmatic color manipulation โ equal numerical steps in OKLCH correspond to equal perceived differences. The Color Converter includes OKLCH output for any hex code you enter.
Common Conversion Examples
| Color | HEX | RGB | HSL |
|---|---|---|---|
| Sky blue | #87CEEB | rgb(135, 206, 235) | hsl(197, 71%, 73%) |
| Tomato | #FF6347 | rgb(255, 99, 71) | hsl(9, 100%, 64%) |
| Olive green | #6B8E23 | rgb(107, 142, 35) | hsl(80, 60%, 35%) |
| Slate gray | #708090 | rgb(112, 128, 144) | hsl(210, 13%, 50%) |
Hex in CSS: Practical Usage
Hex codes work everywhere in CSS that accepts a color value:
/* Text color */
color: #1A1A2E;
/* Background */
background-color: #F0E6D3;
/* Border */
border: 2px solid #3B82F6;
/* Box shadow */
box-shadow: 0 4px 12px #0000001A; /* black at ~10% opacity */
/* With CSS custom properties */
:root {
--brand-primary: #3B82F6;
--brand-dark: #1D4ED8;
}
Case Sensitivity
Hex color codes are case-insensitive in CSS. #3B82F6, #3b82f6, and #3B82f6 all refer to the same color. Most style guides standardize on either all-uppercase or all-lowercase for consistency. Uppercase is traditional; lowercase is popular in modern codebases and many linters prefer it.
Finding Hex Codes
Design tools. Figma, Sketch, and Adobe XD all display hex codes in their color picker panels. Any color swatch in these tools can be copied as hex.
Browser DevTools. Right-click any element on a webpage and inspect it. The CSS panel shows computed color values, which you can click to cycle through formats including hex.
ColorFYI color pages. Every color detail page on ColorFYI โ such as /color/3B82F6/ โ displays the full hex code alongside RGB, HSL, CMYK, and OKLCH values, plus the color's name if it has one.
The Color Converter. If you have a color in RGB or HSL and need the hex equivalent, paste it into the Color Converter for an instant translation.
Key Takeaways
- A hex color code is a six-character hexadecimal number where the first two characters encode the Red channel, the middle two encode Green, and the last two encode Blue.
- Each channel pair ranges from
00(0 intensity) toFF(255 intensity), matching the full 0โ255 range of the RGB model. - High hexadecimal digits indicate high channel intensity; low digits indicate low intensity. Equal values across all three channels produce neutrals (black, gray, white).
- Three-character shorthand (
#RGB) is valid when each pair repeats the same digit โ#336699becomes#369. - Eight-character hex (
#RRGGBBAA) adds an alpha transparency channel; the last two digits range from00(transparent) toFF(opaque). - Use the Color Converter to translate any hex code into RGB, HSL, CMYK, or OKLCH instantly.
- Hex codes are case-insensitive in CSS. Standardize on one convention (all-uppercase or all-lowercase) for consistency.