filter

Term side of the Card.
Topic: Image Handling
Unit title: filter
Categories: Property
Explanation side of the Card

Explanation: The property that applies graphical effects like blur, brightness, contrast or drop shadow to an element. It allows modifying the appearance of images, backgrounds and text, adding visual effects without needing to edit the original content.

Browser compatibility:
  • The chrome browser supports this feature starting from version 53.
  • The edge browser supports this feature starting from version 12.
  • The firefox browser supports this feature starting from version 35.
  • The safari browser supports this feature starting from version 9.1.
Availability: 

Example

Wrongcss
.glass {
  filter: blur(10px);
  background: rgb(255 255 255 / 0.5);
}
Rightcss
.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: fixed child stops sticking to the viewport after a parent gets filter.

Key points

  • Shadows that follow transparent PNG or SVG shapes use filter: drop-shadow(), not box-shadow.
  • Background blur behind glass panels uses backdrop-filter, not filter.
  • 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.

Analytics cookiesWe'd like to use analytics cookies to see which pages are useful. They're set only if you accept. Privacy Policy