Key takeaways
- An 8-digit hex code adds two opacity digits to the end.
- rgb() and hsl() accept alpha after a slash.
- The opacity property fades the whole element, but a transparent color only affects that color.
Sometimes you need a color that lets what is behind it show through: an overlay, a soft shadow or a tinted background. CSS gives you several ways to do it.
8-digit hex
Add two more hex digits to a normal code. They set the opacity from 00 (invisible) to FF (solid). For example, #1E90FF80 is #1E90FF at about 50 percent opacity. Our hex with opacity tool calculates this for any color.
Percentage to hex
Multiply the percentage by 255 and convert to hex. Common values:
| Opacity | Hex | Opacity | Hex |
|---|---|---|---|
| 100% | FF | 50% | 80 |
| 90% | E6 | 40% | 66 |
| 80% | CC | 30% | 4D |
| 70% | B3 | 20% | 33 |
| 60% | 99 | 10% | 1A |
rgb() and hsl() with alpha
Modern CSS lets you write rgb(30 144 255 / 50%) or hsl(210 100% 56% / 0.5). These are easier to read than hex when you want to tweak the opacity later.
color-mix()
If your color lives in a CSS variable, color-mix(in srgb, var(--brand) 50%, transparent) gives you a half-transparent version without hard-coding the digits.
Opacity property vs transparent color
Setting opacity: 0.5 fades an element and everything inside it, including text. A transparent background color only affects the background, so text on top stays fully solid. For overlays and tinted cards, use a transparent color.
Remember contrast
Text on a transparent background takes on whatever is behind it. Test the worst case, for example white text over your lightest image, with the contrast checker.