opacity() CSS Function
The opacity() filter function makes an element partly or fully transparent. 1 or 100% is fully opaque and 0 is fully transparent.
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
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
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.
Desktop





Tablets & Mobile





