DEV Community

Cover image for backdrop-filter in CSS
Ritvik Dubey
Ritvik Dubey

Posted on β€’ Edited on

6 2

backdrop-filter in CSS

This article is about backdrop-filter property in CSS. This will be a short article.

Let's start

The CSS backdrop-filter property is used to apply effects on the area behind an element. In simple words its effect can be seen on the element in the background of the element where this property is applied.

This let's you apply graphical effects. This is unlike the filter property where it applies the effect to the whole element.

While using this the overlaying element must be at least partially transparent so that you can see the effect.(The pro tip:- don't give that div any color)
The overlaying element will get a new sticky context.

Let's break it more to make it even simple,

Let's suppose there is a div name it div-1, which have an image, now there is another div name it div-2, inside div-1 and which is overlaying the div-1. Now apply the filters on the div-2 using backdrop-filter property, so the effect of filters will be on the div-1.

<div id="container">
  <div id="div-1">
    <div id="div-2"></div>
      <img src="https://images.pexels.com/photos/1295959/pexels-photo-1295959.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=650&w=940">
    </div>
</div>
Enter fullscreen mode Exit fullscreen mode
#div-1 {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}
#div-2 {
  width: 60vw;
  height: 40vh;
  position: absolute;
  backdrop-filter: blur(15px); 
}
Enter fullscreen mode Exit fullscreen mode

In this example I have applied blur() filter. It's effect you can see clearly in the pen below.

There are number of filters which you can apply using backdrop-filter property. They are as follows:-

  • backdrop-filter: none;
  • backdrop-filter: blur();
  • backdrop-filter: brightness();
  • backdrop-filter: contrast();
  • backdrop-filter: drop-shadow();
  • backdrop-filter: grayscale();
  • backdrop-filter: hue-rotate();
  • backdrop-filter: invert();
  • backdrop-filter: opacity();
  • backdrop-filter: sepia();
  • backdrop-filter: saturate();

To read more about filters Click here

In the example below I have applied some of these filters

NOTE:-

This doesn't works on Firefox or Internet Explorer.

Cover:- Rajat Gour

Thank you for reading.

Please feel free to share your views about it.

I hope you liked it and found it helpful.

Connect with me on Twitter or LinkedIn

My personal blog blog.ritvikdubey.com

Sentry blog image

How I fixed 20 seconds of lag for every user in just 20 minutes.

Our AI agent was running 10-20 seconds slower than it should, impacting both our own developers and our early adopters. See how I used Sentry Profiling to fix it in record time.

Read more

Top comments (7)

Collapse
 
thisismanaswini profile image
Manaswini β€’

This was like a good revision!! Good one Ritvik πŸ‘Œ

Collapse
 
ritvikdubey27 profile image
Ritvik Dubey β€’

Thank you so much MSπŸ˜‡β€οΈ

Collapse
 
krupapanchal2527 profile image
KrupaPanchal2527 β€’

Very helpful.

Collapse
 
ritvikdubey27 profile image
Ritvik Dubey β€’

I'm glad you found it helpful.!πŸ˜‡

Collapse
 
ljcdev profile image
ljc-dev β€’

Nice article 😁!! A shame it doesn't work on firefox yet. But good to know πŸ‘Œ.

Collapse
 
isarojdahal profile image
Saroj Dahal β€’

Loved it . brother <3

Collapse
 
ritvikdubey27 profile image
Ritvik Dubey β€’

Glad you loved itπŸ˜‡πŸ˜‡β€οΈ

Qodo Takeover

Introducing Qodo Gen 1.0: Transform Your Workflow with Agentic AI

Rather than just generating snippets, our agents understand your entire project context, can make decisions, use tools, and carry out tasks autonomously.

Read full post

Best practices for optimal infrastructure performance with Magento

Running a Magento store? Struggling with performance bottlenecks? Join us and get actionable insights and real-world strategies to keep your store fast and reliable.

Tune in to the full event

DEV is partnering to bring live events to the community. Join us or dismiss this billboard if you're not interested. ❀️