hexcolors

Learn / Blog / Developers

How to add opacity to a hex color in CSS

Use 8-digit hex, rgb with alpha or color-mix, with a full opacity-to-hex table.

November 17, 20261 min readBy the hexcolors team

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:

OpacityHexOpacityHex
100%FF50%80
90%E640%66
80%CC30%4D
70%B320%33
60%9910%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.

The hexcolors teamWe build free color tools and write practical guides. Follow us on X, Instagram and LinkedIn.