Support0

CSS alpha() playground

Change only a color’s opacity with alpha(). Set a new alpha or multiply the original with calc(alpha * …), preserving its components and color space.

Ask AI

CSS alpha() playground

Response generated with openai/gpt-5.4-nano. AI can make mistakes. Always review the result.
Original
Result with alpha()
HTML
<div class="alpha-demo"></div>
Tailwind CSS
Examples for Tailwind CSS 4.3 with the default theme. Custom values keep arbitrary classes when there is no equivalent utility. Changing the theme can change utility values.
<div class="inline-48 aspect-square rounded-full bg-[color:alpha(from_oklch(65%_0.2_260_/_0.8)_/_50%)]"></div>
CSS
.alpha-demo {
  --origin-color: oklch(65% 0.2 260 / 0.8);
  background-color: alpha(from var(--origin-color) / 50%);
  inline-size: 12rem;
  aspect-ratio: 1;
  border-radius: 50%;
}

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.

  1. Origin color

    oklch(65% 0.2 260 / 0.8): three components and alpha 0.8.

  2. Alpha operation

    Setting 50% gives 0.5; multiplying by 0.5 gives 0.4.

  3. Compositing

    The resulting color reveals the layers underneath.

Static conceptual diagramThe color components stay the same. The background contributes to the final appearance, even though it is not an alpha() argument. The samples below apply real CSS.

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.

All three colors preserve lightness, chroma and hue in OKLCH. The pattern reveals transparency; labels state the expected alpha values. If an expression is rejected, its sample is omitted and a notice appears.
Origin 0.8, replacement 0.5 and multiplication 0.4
<div class="alpha-scene-values">
  <div class="original">
    <p>Original · alpha 0.8</p>
    <div class="stage" aria-hidden="true"><div class="paint"></div></div>
    <p class="unsupported">This expression is not applied in the current browser; the sample is not drawn.</p>
  </div>
  <div class="fixed">
    <p>Fixed alpha · 0.5</p>
    <div class="stage" aria-hidden="true"><div class="paint"></div></div>
    <p class="unsupported">This expression is not applied in the current browser; the sample is not drawn.</p>
  </div>
  <div class="relative">
    <p>Relative alpha · 0.4</p>
    <div class="stage" aria-hidden="true"><div class="paint"></div></div>
    <p class="unsupported">This expression is not applied in the current browser; the sample is not drawn.</p>
  </div>
</div>
:root {
  color-scheme: light dark;
}

.alpha-scene-values {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;

  > div {
    flex: 1 1 12rem;
    min-inline-size: 0;
    display: grid;
    align-content: start;
    gap: 0.5rem;
  }

  p {
    margin: 0;
    color: light-dark(oklch(0.22 0.01 95), oklch(0.95 0.01 95));
    font: 1rem/1.6 system-ui, sans-serif;
    overflow-wrap: anywhere;
  }

  .stage {
    display: grid;
    min-block-size: 6rem;
    border: 1px solid light-dark(oklch(0.84 0.01 95), oklch(0.36 0.024 260));
    background: repeating-conic-gradient(#fff 0 25%, #dbeafe 0 50%) 0 / 1.5rem 1.5rem;
  }

  .paint {
    display: none;
    padding: min(1rem, 5vi);
    place-items: center;
    color: #0f172a;
    font: 600 1rem/1.6 system-ui, sans-serif;
    overflow-wrap: anywhere;
  }

  @supports (background-color: oklch(65% 0.2 260 / 0.8)) {
    .original .paint {
      display: grid;
      background-color: oklch(65% 0.2 260 / 0.8);
    }

    .original .unsupported {
      display: none;
    }
  }

  @supports (background-color: alpha(from oklch(65% 0.2 260 / 0.8) / 50%)) {
    .fixed .paint {
      display: grid;
      background-color: alpha(from oklch(65% 0.2 260 / 0.8) / 50%);
    }

    .fixed .unsupported {
      display: none;
    }
  }

  @supports (background-color: alpha(from oklch(65% 0.2 260 / 0.8) / calc(alpha * 0.5))) {
    .relative .paint {
      display: grid;
      background-color: alpha(from oklch(65% 0.2 260 / 0.8) / calc(alpha * 0.5));
    }

    .relative .unsupported {
      display: none;
    }
  }

  @media (forced-colors: active) {
    .stage {
      border: 1px solid CanvasText;
      background: Canvas;
    }

    .paint {
      color: CanvasText;
      background-color: Canvas;
    }
  }
}

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.

Both samples use exactly the same expression and alpha 0.4. Only the background changes. Compositing is native; it is not simulated with a precalculated opaque color.
The same alpha over two opaque surfaces
<div class="alpha-scene-backgrounds">
  <div class="light">
    <p>Over white · alpha 0.4</p>
    <div class="stage" aria-hidden="true"><div class="paint"></div></div>
    <p class="unsupported">This expression is not applied in the current browser; the sample is not drawn.</p>
  </div>
  <div class="dark">
    <p>Over dark blue · alpha 0.4</p>
    <div class="stage" aria-hidden="true"><div class="paint"></div></div>
    <p class="unsupported">This expression is not applied in the current browser; the sample is not drawn.</p>
  </div>
</div>
:root {
  color-scheme: light dark;
}

.alpha-scene-backgrounds {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;

  > div {
    flex: 1 1 12rem;
    min-inline-size: 0;
    display: grid;
    align-content: start;
    gap: 0.5rem;
  }

  p {
    margin: 0;
    color: light-dark(oklch(0.22 0.01 95), oklch(0.95 0.01 95));
    font: 1rem/1.6 system-ui, sans-serif;
    overflow-wrap: anywhere;
  }

  .stage {
    display: grid;
    min-block-size: 6rem;
    border: 1px solid light-dark(oklch(0.84 0.01 95), oklch(0.36 0.024 260));
    background: repeating-conic-gradient(#fff 0 25%, #dbeafe 0 50%) 0 / 1.5rem 1.5rem;
  }

  .paint {
    display: none;
    padding: min(1rem, 5vi);
    place-items: center;
    color: #0f172a;
    font: 600 1rem/1.6 system-ui, sans-serif;
    overflow-wrap: anywhere;
  }

  .light .stage {
    background: #fff;
  }

  @supports (background-color: alpha(from oklch(65% 0.2 260 / 0.8) / calc(alpha * 0.5))) {
    .light .paint {
      display: grid;
      background-color: alpha(from oklch(65% 0.2 260 / 0.8) / calc(alpha * 0.5));
    }

    .light .unsupported {
      display: none;
    }
  }

  .dark .stage {
    background: #172554;
  }

  @supports (background-color: alpha(from oklch(65% 0.2 260 / 0.8) / calc(alpha * 0.5))) {
    .dark .paint {
      display: grid;
      background-color: alpha(from oklch(65% 0.2 260 / 0.8) / calc(alpha * 0.5));
    }

    .dark .unsupported {
      display: none;
    }
  }

  @media (forced-colors: active) {
    .stage {
      border: 1px solid CanvasText;
      background: Canvas;
    }

    .paint {
      color: CanvasText;
      background-color: Canvas;
    }
  }
}

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 text belongs to the sample

This expression is not applied in the current browser; the sample is not drawn.

opacity: 0.5 · background and text

This text belongs to the sample

This expression is not applied in the current browser; the sample is not drawn.

The left derives the background from alpha 0.8 to 0.4 and keeps the text opaque. The right keeps background alpha at 0.8 and applies opacity: 0.5 to the group, fading its text too. The outer labels remain opaque for comparison.
Background at 0.4 versus group at 0.5
<div class="alpha-scene-opacity">
  <div class="color-only">
    <p>alpha() · background only</p>
    <div class="stage"><div class="paint"><span>This text belongs to the sample</span></div></div>
    <p class="unsupported">This expression is not applied in the current browser; the sample is not drawn.</p>
  </div>
  <div class="whole-group">
    <p>opacity: 0.5 · background and text</p>
    <div class="stage"><div class="paint"><span>This text belongs to the sample</span></div></div>
    <p class="unsupported">This expression is not applied in the current browser; the sample is not drawn.</p>
  </div>
</div>
:root {
  color-scheme: light dark;
}

.alpha-scene-opacity {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;

  > div {
    flex: 1 1 12rem;
    min-inline-size: 0;
    display: grid;
    align-content: start;
    gap: 0.5rem;
  }

  p {
    margin: 0;
    color: light-dark(oklch(0.22 0.01 95), oklch(0.95 0.01 95));
    font: 1rem/1.6 system-ui, sans-serif;
    overflow-wrap: anywhere;
  }

  .stage {
    display: grid;
    min-block-size: 6rem;
    border: 1px solid light-dark(oklch(0.84 0.01 95), oklch(0.36 0.024 260));
    background: repeating-conic-gradient(#fff 0 25%, #dbeafe 0 50%) 0 / 1.5rem 1.5rem;
  }

  .paint {
    display: none;
    padding: min(1rem, 5vi);
    place-items: center;
    color: #0f172a;
    font: 600 1rem/1.6 system-ui, sans-serif;
    overflow-wrap: anywhere;
  }

  @supports (background-color: alpha(from rgb(30 90 180 / 0.8) / calc(alpha * 0.5))) {
    .color-only .paint {
      display: grid;
      background-color: alpha(from rgb(30 90 180 / 0.8) / calc(alpha * 0.5));
    }

    .color-only .unsupported {
      display: none;
    }
  }

  @supports (background-color: rgb(30 90 180 / 0.8)) {
    .whole-group .paint {
      display: grid;
      background-color: rgb(30 90 180 / 0.8);
      opacity: 0.5;
    }

    .whole-group .unsupported {
      display: none;
    }
  }

  @media (forced-colors: active) {
    .stage {
      border: 1px solid CanvasText;
      background: Canvas;
    }

    .paint {
      color: CanvasText;
      background-color: Canvas;
    }
  }
}

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.

Fixed alpha gives 0.5; relative alpha and the mix with transparent give 0.4. Mixing with white changes the components and gives alpha 0.9: it lightens the color instead of only making it transparent. Each syntax has its own check.
Replace, multiply, mix and lighten
<div class="alpha-scene-mixing">
  <div class="fixed">
    <p>Fixed alpha · 0.5</p>
    <div class="stage" aria-hidden="true"><div class="paint"></div></div>
    <p class="unsupported">This expression is not applied in the current browser; the sample is not drawn.</p>
  </div>
  <div class="relative">
    <p>Relative alpha · 0.4</p>
    <div class="stage" aria-hidden="true"><div class="paint"></div></div>
    <p class="unsupported">This expression is not applied in the current browser; the sample is not drawn.</p>
  </div>
  <div class="mixed">
    <p>Mix with transparent · alpha 0.4</p>
    <div class="stage" aria-hidden="true"><div class="paint"></div></div>
    <p class="unsupported">This expression is not applied in the current browser; the sample is not drawn.</p>
  </div>
  <div class="white">
    <p>Mix with white · alpha 0.9</p>
    <div class="stage" aria-hidden="true"><div class="paint"></div></div>
    <p class="unsupported">This expression is not applied in the current browser; the sample is not drawn.</p>
  </div>
</div>
:root {
  color-scheme: light dark;
}

.alpha-scene-mixing {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;

  > div {
    flex: 1 1 12rem;
    min-inline-size: 0;
    display: grid;
    align-content: start;
    gap: 0.5rem;
  }

  p {
    margin: 0;
    color: light-dark(oklch(0.22 0.01 95), oklch(0.95 0.01 95));
    font: 1rem/1.6 system-ui, sans-serif;
    overflow-wrap: anywhere;
  }

  .stage {
    display: grid;
    min-block-size: 6rem;
    border: 1px solid light-dark(oklch(0.84 0.01 95), oklch(0.36 0.024 260));
    background: repeating-conic-gradient(#fff 0 25%, #dbeafe 0 50%) 0 / 1.5rem 1.5rem;
  }

  .paint {
    display: none;
    padding: min(1rem, 5vi);
    place-items: center;
    color: #0f172a;
    font: 600 1rem/1.6 system-ui, sans-serif;
    overflow-wrap: anywhere;
  }

  @supports (background-color: alpha(from rgb(30 90 180 / 0.8) / 50%)) {
    .fixed .paint {
      display: grid;
      background-color: alpha(from rgb(30 90 180 / 0.8) / 50%);
    }

    .fixed .unsupported {
      display: none;
    }
  }

  @supports (background-color: alpha(from rgb(30 90 180 / 0.8) / calc(alpha * 0.5))) {
    .relative .paint {
      display: grid;
      background-color: alpha(from rgb(30 90 180 / 0.8) / calc(alpha * 0.5));
    }

    .relative .unsupported {
      display: none;
    }
  }

  @supports (background-color: color-mix(in srgb, rgb(30 90 180 / 0.8) 50%, transparent)) {
    .mixed .paint {
      display: grid;
      background-color: color-mix(in srgb, rgb(30 90 180 / 0.8) 50%, transparent);
    }

    .mixed .unsupported {
      display: none;
    }
  }

  @supports (background-color: color-mix(in srgb, rgb(30 90 180 / 0.8) 50%, white)) {
    .white .paint {
      display: grid;
      background-color: color-mix(in srgb, rgb(30 90 180 / 0.8) 50%, white);
    }

    .white .unsupported {
      display: none;
    }
  }

  @media (forced-colors: active) {
    .stage {
      border: 1px solid CanvasText;
      background: Canvas;
    }

    .paint {
      color: CanvasText;
      background-color: Canvas;
    }
  }
}

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.

The white background fixes the compositing context. Without alpha(), relative RGB or the explicit fallback is used and the notice remains. If --brand changes, the fixed fallback must be updated; it is not an automatic conversion of any color.
Derive a layer without fading its content
<div class="alpha-scene-recipe">
  <p>The background is translucent; this text retains its opacity.</p>
  <p class="fallback">Fallback active: relative RGB or explicit color; alpha() is not applied.</p>
</div>
.alpha-scene-recipe {
  --brand: rgb(30 90 180 / 0.8);
  --wash: rgb(30 90 180 / 0.4);
  padding: min(1rem, 5vi);
  border: 2px solid #1e5ab4;
  border-radius: 16px;
  corner-shape: squircle;
  color: #0f172a;
  background-color: #fff;
  background-image: linear-gradient(var(--wash), var(--wash));
  font: 1rem/1.6 system-ui, sans-serif;
  overflow-wrap: anywhere;

  p {
    margin: 0;
  }

  @supports (color: rgb(from rgb(30 90 180 / 0.8) r g b / calc(alpha * 0.5))) {
    --wash: rgb(from var(--brand) r g b / calc(alpha * 0.5));
  }

  @supports (color: alpha(from rgb(30 90 180 / 0.8) / calc(alpha * 0.5))) {
    --wash: alpha(from var(--brand) / calc(alpha * 0.5));

    .fallback {
      display: none;
    }
  }

  @media (forced-colors: active) {
    color: CanvasText;
    background: Canvas;
    border-color: CanvasText;
  }
}

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.