Favorites

opacity() CSS Function

opacity()
CSS FunctionThis function is supported by all modern browsers.
Updated 21st November 2026

The opacity() filter function makes an element partly or fully transparent. 1 or 100% is fully opaque and 0 is fully transparent.

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 opacity() CSS function is a filter function that makes an element partly or fully transparent. It is used with the filter property, and also with backdrop-filter, where it affects what is shown behind the element. Its argument is a number or a percentage: 1 or 100% leaves the element unchanged, 0 or 0% makes it completely transparent, and values in between give partial transparency. Values above 100% are clamped to 100%, and negative values are invalid.

The result looks the same as the opacity property, and like the property it affects the element together with all of its content and children. The difference is that, as a filter function, opacity() can be combined with other filters in a single filter chain, where the order matters, for example filter: blur(2px) opacity(50%). Some browsers can also accelerate filters on the GPU. For simple fades, the opacity property is usually the simpler choice.

To make only a color transparent, such as a background color, rather than the whole element, use a color with an alpha value instead, for example rgb(255 0 0 / 50%). opacity() cannot be used inside color functions.

.faded {
  filter: opacity(40%);
}

/* Combined with other filter functions */
.disabled {
  filter: grayscale(1) opacity(0.6);
}

/* Fade in smoothly on hover */
.card img {
  filter: opacity(0.7);
  transition: filter 0.3s;
}

.card:hover img {
  filter: opacity(1);
}

Interactive Demo

Sunset
Demo Code
HTML Code
<div class="demo-checker">
	<img class="demo-element" src="/css-properties/images/sunset.jpg" alt="Sunset">
</div>
CSS Code
.demo-checker {
	width: 280px;
	padding: 10px;
	background: repeating-conic-gradient(#ddd 0 25%, #fff 0 50%) 0 0 / 20px 20px;
}
.demo-element {
	width: 260px;
	display: block;
	border-radius: 6px;
	filter: opacity(1);
}

Syntax

opacity() = opacity( [ <number> | <percentage> ]? )

Values

  • amountThe amount of the conversion, specified as a <number> or a <percentage>. A value of 0% is completely transparent, while a value of 100% leaves the input unchanged. Values between 0% and 100% are linear multipliers on the effect. The lacuna value for interpolation is 1.

Example

<div class="container">
<div class="box full-opacity">100% (Solid)</div>
<div class="box partial-opacity">50% (Translucent)</div>
<div class="box low-opacity">10% (Faded)</div>
</div>
/* Layout styling */
.container {
display: flex;
gap: 20px;
padding: 20px;
background-image: linear-gradient(45deg, #ccc 25%, transparent 25%),
linear-gradient(-45deg, #ccc 25%, transparent 25%);
background-size: 20px 20px; /* Checkerboard background to show transparency */
}

.box {
width: 150px;
height: 150px;
display: flex;
align-items: center;
justify-content: center;
background-color: #3498db;
color: white;
font-weight: bold;
border-radius: 8px;
}

/* Opacity Filter Examples */
.full-opacity {
filter: opacity(100%);
}

.partial-opacity {
filter: opacity(0.5); /* You can use decimals or percentages */
}

.low-opacity {
filter: opacity(10%);
}
Open in editor

Browser Support

The following information will show you the current browser support for the CSS opacity() function. Hover over a browser icon to see the version that first introduced support for this CSS function.

This function is supported by all modern browsers.

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.