Educational guide to alpha()
Color transparency with CSS
Derive a transparent variant of a color without rewriting its channels. Learn to set or multiply alpha, distinguish it from opacity and check the result against its actual background.
Mental model
An origin color, a new alpha and a background to paint it on.
- Origin color
oklch(65% 0.2 260 / 0.8): three components and alpha 0.8.
- Alpha operation
Setting 50% gives 0.5; multiplying by 0.5 gives 0.4.
- Compositing
The resulting color reveals the layers underneath.
One channel, two operations
A fixed value replaces the previous alpha; an expression using alpha takes it as a numeric input.
The result is still a color
Compositing happens when painting. A color with alpha 0.4 does not guarantee the same appearance or contrast on every surface.
alpha(from color / value) returns a color: it preserves the origin components and color space, changing only its alpha channel. You can use it for backgrounds, borders, shadows or text. The function does not reduce the opacity of an entire element or choose a contrasting color.
Fixed and relative alpha
The same 50% can express two different results.
/ 50% and / 0.5 set alpha to 0.5, even if the origin has 0.8. In / calc(alpha * 0.5), alpha represents the original alpha as a number: 0.8 × 0.5 = 0.4. If the origin has alpha 0, multiplying cannot make it visible again; replacing it with 0.5 can.
Origin 0.8, replacement 0.5 and multiplication 0.4
Original · alpha 0.8
This expression is not applied in the current browser; the sample is not drawn.
Fixed alpha · 0.5
This expression is not applied in the current browser; the sample is not drawn.
Relative alpha · 0.4
This expression is not applied in the current browser; the sample is not drawn.
alpha is a number from 0 to 1, not a percentage you need to divide by 100. In these operations, results outside the range are clamped to 0–1. The lab uses a 0–100% range for its control, while CSS accepts more general expressions.
Compositing over backgrounds
Preserving a color does not preserve its final appearance.
When painting a translucent layer, the visible background contributes to the result. The same color with alpha 0.4 over white and dark blue produces different appearances. Overlapping layers also accumulate coverage: two layers with alpha 0.5 are not equivalent to one layer with alpha 0.5.
The same alpha over two opaque surfaces
Over white · alpha 0.4
This expression is not applied in the current browser; the sample is not drawn.
Over dark blue · alpha 0.4
This expression is not applied in the current browser; the sample is not drawn.
Check text contrast against the final composited background, including themes, images and states. Alpha is neither lightness nor a contrast measure. A layer at 0% is invisible, but its node and interaction remain; do not use transparency as a substitute for hiding content or disabling a control.
Transparent color versus opacity
Changing a background and fading an entire group have different scopes.
alpha() modifies the color it is applied to. In background-color, descendants keep their own opacity. opacity composites the element together with its descendants and fades the group: text, borders, images and controls included. A value below 1 also creates a stacking context.
Background at 0.4 versus group at 0.5
alpha() · background only
This expression is not applied in the current browser; the sample is not drawn.
opacity: 0.5 · background and text
This expression is not applied in the current browser; the sample is not drawn.
Use color alpha for a translucent surface that should keep text readable. Use opacity when you deliberately want to fade the whole group; reducing it does not change semantics, focus or the interactive area.
Mixing with transparent
A mix can multiply transparency, but cannot replace every alpha operation.
color-mix(in srgb, origin 50%, transparent) keeps half the original alpha: alpha 0.8 becomes 0.4. Here it matches multiplying by 0.5, not setting 50%. Mixing uses premultiplied alpha interpolation; transparent does not add a black tint in this example.
Replace, multiply, mix and lighten
Fixed alpha · 0.5
This expression is not applied in the current browser; the sample is not drawn.
Relative alpha · 0.4
This expression is not applied in the current browser; the sample is not drawn.
Mix with transparent · alpha 0.4
This expression is not applied in the current browser; the sample is not drawn.
Mix with white · alpha 0.9
This expression is not applied in the current browser; the sample is not drawn.
alpha() keeps the origin space without asking for an interpolation space. color-mix() returns a color in the chosen space; converting an origin from another space can change its representation and rendering. This practical equivalence therefore uses an sRGB origin, normal weights and complete channels, and is not generalized to every mix.
A surface with fallback
A valid base and progressive enhancements for the exact value you need.
This recipe defines an RGB origin with alpha 0.8 and a fallback variant with alpha 0.4. It first enhances with relative rgb(), if that operation is accepted; then it uses alpha() when its calc() form is accepted. The color layer is painted over an explicit white base and the text retains its opacity.
Derive a layer without fading its content
The background is translucent; this text retains its opacity.
Fallback active: relative RGB or explicit color; alpha() is not applied.
var(--wash, fallback) does not validate the content of --wash when the variable is defined. Storing an unsupported function in a token can invalidate the consuming property at computed value time. Guard the advanced assignment with @supports and also check that actual tokens contain valid colors.
Common mistakes
Diagnose the operation, scope and painting context.
50% does not keep half the origin
- Expected result
- An origin with alpha 0.8 should become 0.4.
- Cause
- / 50% replaces alpha with 0.5.
- Solution
- Use / calc(alpha * 0.5) to multiply the original alpha.
The text fades too
- Expected result
- Only the background should reveal the underlying surface.
- Cause
- opacity is applied to the entire container.
- Solution
- Derive the alpha of background-color and keep the group opaque.
The same variant loses readability on another background
- Expected result
- Text should remain readable in every theme or surface.
- Cause
- The translucent color is composited with a different background.
- Solution
- Check composited contrast and adjust the background, alpha or text color.
A variable loses its fallback
- Expected result
- The base should still paint without advanced support.
- Cause
- A defined variable contains a function the consumer cannot resolve.
- Solution
- Define a valid base and change the token only inside @supports for that expression.
Support and compatibility
The catalog and a syntax check answer different questions.
MDN lists alpha() as Baseline Newly Available since September 2026; BCD lists Chrome 152, Firefox 155 and Safari 27. The card queries the Web Platform Status catalog. Check current versions and data before publishing or setting a support minimum.
Test fixed and relative alpha, the calc(alpha * …) operation, relative RGB and color-mix() separately, as well as the origin color in use. Accepting alpha(from red / 50%) does not certify every nested expression, valid variables, contrast or bug-free implementation. @supports reports syntax acceptance; previews check its application in the browser you are using.
For a known color you can write its variant with explicit alpha. For derivations, relative colors or mixing with transparent may work under their own checks, with the differences described above. The function is described in CSS Color 5, an evolving draft; keep a useful fallback where needed.