Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between "opacity" and "filter: opacity()"

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?

like image 420
Bram Vanroy Avatar asked Dec 01 '13 08:12

Bram Vanroy


People also ask

What is opacity filter?

The opacity() function is an inbuilt function which is used to apply a filter to the image to set the transparency of the image.

What is the difference between opacity and transparency in CSS?

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.

What is the difference between opacity and Alpha?

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.

What is the difference between opacity and background?

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.


2 Answers

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>
like image 104
Arman Nisch Avatar answered Oct 17 '22 12:10

Arman Nisch


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.

like image 4
Hit-or-miss Avatar answered Oct 17 '22 13:10

Hit-or-miss