filter
Example
.glass {
filter: blur(10px);
background: rgb(255 255 255 / 0.5);
}.glass {
backdrop-filter: blur(10px);
background: rgb(255 255 255 / 0.5);
}filter blurs the element and its text; backdrop-filter blurs only what is behind it.
Common mistakes
filter: blur()blurs the text of the element too, not just the background.- A
position: fixedchild stops sticking to the viewport after a parent getsfilter.
Key points
- Shadows that follow transparent PNG or SVG shapes use
filter: drop-shadow(), notbox-shadow. - Background blur behind glass panels uses
backdrop-filter, notfilter. - Large animated
blur()values are avoided on big areas, because they are expensive to paint.
Interview questions
Why does filter break position: fixed?
Any filter other than 'none' makes the element a containing block for fixed and absolute descendants, so they position against it.
Can I combine several filter functions?
Yes. List them separated by spaces, like filter: grayscale(1) contrast(2); they apply in order.