alpha() CSS Function
The alpha() function takes an existing color and returns it with a different opacity, such as alpha(from var(--brand) / 50%).
Description
The alpha() CSS function takes an existing color and returns the same color with a different alpha (opacity) value. It always uses relative color syntax: the keyword from, the origin color, a slash, and the new alpha value, for example alpha(from var(--brand) / 50%). The red, green and blue (or other) components of the origin color pass through unchanged; only the transparency changes.
The alpha value can be a number from 0 to 1, a percentage, or a calculation. Inside the calculation, the keyword alpha stands for the origin color's current alpha, so calc(alpha * 0.5) halves whatever opacity the color already has. This is especially useful with custom properties, because you can create transparent variants of a theme color without knowing which color format it was written in.
Before alpha(), the same result needed the longer relative syntax of a specific color function, such as rgb(from var(--brand) r g b / 50%). alpha() works with any color and keeps its original color space. It is a recent addition, so provide a fallback color first.
:root {
--brand: oklch(60% 0.2 260);
}
.overlay {
background-color: alpha(from var(--brand) / 20%);
}
.border {
border-color: alpha(from var(--brand) / calc(alpha * 0.5));
}
Interactive Demo
Syntax
alpha() = alpha( from <color> / [ <alpha-value> | none ] )
Values
- from <color>The origin color. Its color components are kept unchanged.
- <alpha-value>The new alpha after a slash: a <number> from 0 to 1, a <percentage>, or a calc() expression. The keyword alpha refers to the origin color's alpha as a number.
Example
Browser Support
The following information will show you the current browser support for the CSS alpha() function. Hover over a browser icon to see the version that first introduced support for this CSS function.
Desktop





Tablets & Mobile





