Advertisement
  1. Web Design
  2. CSS
Webdesign

Having Fun With Tomorrow’s CSS: Backdrop Filters

by
Difficulty:IntermediateLength:ShortLanguages:

In this tutorial we will look into an emerging CSS toy going by the name of Backdrop Filter.

The backdrop-filter proposal is heavily influenced by the Apple design language, particularly that frosty-transparent-blurry-background seen in their most recent iOS and macOS interfaces. You’ll have noticed it in the Dock, the Contextual Menu, and the Notification centre.

Backdrop filter is currently baked under CSS Filters Level 2, and at the time of the writing, it only works work in Safari 9 with the -webkit- prefix, and Chrome as well as Opera by enabling the “Experimental Web Platform Features” under the chrome://flags menu.

Chrome Flag Menu

Using Backdrop Filter

Backdrop-filter is included as part of the CSS Filters specification and thus, similarly to the filter property, it inherits all the familiar filtering functions such grayscale()blur(), and sepia(). The only difference here is that it will affect the elements underneath the selected element.

To use it, we will need at least two elements; the first element will be the target, while the second will lie underneath it. For example:

Set a background in the first element with low opacity so we can add backdrop-filter with a function, for example, grayscale() to turn the backdrop black and white.

Notice in the following demo that descendants of the .filter elements (a button in this case) remain crisp despite the blur() function addition. This is an advantage backdrop-filter has over the filter property; where all descendants are impacted.

Note: image here taken from tutorial How to Create a Little Red Riding Hood Inspired Fairytale Illustration in Paint Tool SAI.

Combining Multiple Filters

Combining two filter functions in a single declaration is also acceptable. For example, keeping our blur(), but adding the grayscale() function to strip the backdrop of color.

Other functions you can add into the mix include:

  • brightness(): accepting a number from 0 to infinity, or percentage. Any number below 1, e.g. 0.8, will darken the element, and specifying any number above 1 will lighten the element.
  • contrast(): accepts a number and percentage which works similar to the brightness() function, except this function defines the element contrast.
  • invert(): this function generates the opposite or negative colors of the backdrop. Likewise, the function also accepts a number and percentage as the value.

Advanced Filter With SVG

If you can’t find the desired effect from these default functions, you can always add a more advanced filter through SVG. Create an SVG filter with a unique ID, and save it in an .svg file:

Refer the filter with the url() function, like so.

Unfortunately, adding filter with the url() function does not seem to work in any browser at the persent time. But once properly implemented, the image should look like this.

Custom filter with SVG. 

What to Build?

There are a number of practical implementations on the web where we could apply backdrop filters in a more meaningful way than just being a garnish. One good example is Medium, which blurs the post image cover as well as images within the post content before the image is fully loaded.

A post in Medium with the title image cover and the excerpt
Blurry Image in Medium.com

Another great real-world example is Facebook, which blurs images with mature, inappropriate, or disturbing content, before users have consented to viewing the image in full.

Facebook blurring a violent image following their Facebook Community Standard guideline.

Conclusion

Over the years, CSS has been enhanced with new specifications that enable designers to build more compelling interfaces on the web. Transforms, transitions, and animations have all played their part, and now Backdrop Filters are coming our way too.

Although it maybe too early to use backdrop-filter in production, these demos show that we will soon be able to apply filter effects to elements in a more simplified way and ultimately less reliant on heavy JavaScript or Canvas libraries. Until then, follow the Webkit Blog for updates on this and other projects.

Further Resources

Advertisement
Advertisement
Looking for something to help kick start your next project?
Envato Market has a range of items for sale to help get you started.