Favorites

alpha() CSS Function

alpha()
CSS FunctionThis function is supported in some modern browsers, but not all.
Updated 21st November 2026

The alpha() function takes an existing color and returns it with a different opacity, such as alpha(from var(--brand) / 50%).

Looks like you're using an ad blocker, and that's fine! Ads help keep CSS Portal's generators and references free, so if the site's useful to you, visit our Support page to see other ways to help.

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

Colour swatch
Demo Code
HTML Code
<div class="demo-checker">
	<div class="demo-element">Colour swatch</div>
</div>
CSS Code
.demo-checker {
	width: 296px;
	padding: 18px;
	box-sizing: border-box;
	background: repeating-conic-gradient(#ddd 0 25%, #fff 0 50%) 0 0 / 20px 20px;
}
.demo-element {
	width: 260px;
	padding: 18px;
	border-radius: 8px;
	font-size: 16px;
	font-weight: bold;
	color: #fff;
	text-shadow: 0 1px 2px rgb(0 0 0 / 40%);
	background-color: alpha(from #f72585 / 100%);
}

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

<div class="wrap">
<h1>CSS alpha() examples</h1>
<div class="grid">
<div class="card">
<div class="stage"><div class="sw full">100%</div></div>
<div class="label">var(--brand)</div>
</div>
<div class="card">
<div class="stage"><div class="sw a60">60%</div></div>
<div class="label">alpha(from var(--brand) / 60%)</div>
</div>
<div class="card">
<div class="stage"><div class="sw a25">25%</div></div>
<div class="label">alpha(from var(--brand) / 25%)</div>
</div>
<div class="card">
<div class="stage"><div class="sw half">half</div></div>
<div class="label">alpha(from var(--brand) / calc(alpha * 0.5))</div>
</div>
</div>
</div>
/* Base demo layout */
* { box-sizing: border-box; }

body {
margin: 24px;
font-family: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial;
background: #f5f7fb;
color: #102a43;
}

.wrap {
max-width: 860px;
margin: 0 auto;
}

h1 {
font-size: 20px;
margin: 0 0 16px;
}

.grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
gap: 16px;
}

.card {
background: #fff;
border-radius: 12px;
padding: 16px;
box-shadow: 0 6px 18px rgba(16, 42, 67, 0.08);
}

.label {
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, monospace;
font-size: 12px;
color: #486581;
margin-top: 10px;
word-break: break-word;
}

.note {
font-size: 13px;
color: #486581;
margin-top: 14px;
}

/* alpha() examples */
.sw {
height: 80px;
border-radius: 8px;
display: grid;
place-items: center;
font-weight: 700;
}

:root {
--brand: oklch(60% 0.2 260);
}

.stage {
padding: 10px;
border-radius: 10px;
/* checkerboard so transparency is visible */
background: repeating-conic-gradient(#e2e8f0 0 25%, #fff 0 50%) 0 0 / 16px 16px;
}

.full { background-color: var(--brand); color: #fff; }
.a60 { background-color: rgb(59 99 235 / 60%); background-color: alpha(from var(--brand) / 60%); }
.a25 { background-color: rgb(59 99 235 / 25%); background-color: alpha(from var(--brand) / 25%); }
.half { background-color: rgb(59 99 235 / 50%); background-color: alpha(from var(--brand) / calc(alpha * 0.5)); }
Open in editor

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.

This function is supported in some modern browsers, but not all.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported

Looks like you're using an ad blocker, and that's fine! Ads help keep CSS Portal's generators and references free, so if the site's useful to you, visit our Support page to see other ways to help.