Most of us know the simple opacity
CSS rule, but recently I stumbled upon filter
which can have opacity(amount)
as it value - among other things. But what exactly is the difference between the two?
The opacity() function is an inbuilt function which is used to apply a filter to the image to set the transparency of the image.
Opacity is a measure of how opaque an item is and transparency is a measure of how transparent it appears. Both work nearly the same way but at 100% transparent, the element will be completely invisible, while with the opacity set to 100% it be fully visible.
The opacity-level describes the transparency-level, where 1 is not transparant at all, 0.5 is 50% see-through, and 0 is completely transparent. Alpha Channel RGBA color values are an extension of RGB color values with an alpha channel - which specifies the opacity of the object.
one ( opacity ) is a property; the other is the component of the value of a color property, such as background-color , box-shadow-color , or border-color . Most importantly, opacity affects the entire element it is applied to, whereas rgba affects only one aspect.
filter: opacity() is similar to the more established opacity property; the difference is that with filter: opacity(), some browsers provide hardware acceleration for better performance. Negative values are not allowed.
filter: opacity() applies transparency. A value of 0% is completely transparent. A value of 100% leaves the input unchanged. Values between 0% and 100% are linear multipliers on the effect. This is equivalent to multiplying the input image samples by amount. If the “amount” parameter is missing, a value of 100% is used.
Source: https://css-tricks.com/almanac/properties/f/filter/
/*
* -----------
* filter: opacity([ <number> or <percentage> ])
* -----------
*/
.filter-opacity {
filter: opacity(0.3);
height: 5rem;
width: 5rem;
background-color: mediumvioletred;
}
/*
* -----------
* standard opacity
* -----------
*/
.just-opacity {
opacity: 0.3;
height: 5rem;
width: 5rem;
background-color: lawngreen;
}
<div class="filter-opacity">
filter-opacity
</div>
<div class="just-opacity">
just-opacity
</div>
I've found some difference between them both, especially in the Chrome browser.
If we set the CSS opacity
property to an iframe
tag, then we'll not be able to click any links inside this frame (I guess, it's a protection from clickjacking
attack) while filter: opacity(0)
allows us to click any links. I don't know, maybe it's an omission from Chrome developers' side.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With