Two Ways to Create a Frosted Glass Effect in CSS

In this tutorial I’m going to show you how to create a frosted glass effect in CSS. You’ll have seen this in action in UIs such as on MacOS and iOS, even Windows nowadays, so it’s definitely a trending effect. We can emulate frosted glass in websites using CSS, and in this tutorial I’ll show you two ways to do it.

Frosted Glass Effect in CSS

[embedded content]

Method 1

The first method has quite wide browser support, but it requires more CSS than the second approach we’ll look at.

Begin by creating a div with a class of .container. We’ll use this to represent our frosted glass pane. Then, apply a background image to the body element. To this background you’ll need to apply:

We do this because children of the body will inherit this background image and we want to keep it at the same size.

We’re now going to create a pseudo element on our .container, and that’s what’s going to give us our blur. So, we apply the following:

This gives us an element which covers the container element. Now it’s time to add some colour, which we’ll do using a box-shadow:

And to give us a frosted effect we add a blur filter:

This gives us most of what we want, but it’s not quite there yet. We now need (as we discussed earlier) to set an inherited background to both the pseudo element and its parent.

With a few more optional tweaks, here’s the end result:

Method 2

Now for an alternative method which uses a little less styling, but enjoys slightly less browser support. We begin with the same .container element and apply the same cover background image to the body element.

Then we turn our attention to a CSS property called backdrop-filter. We begin by adding some display styles to our .container, including a background colour of whatever we like (let’s go for a pale white):

Then we add the filter (you might need to include the appropriate prefix for your browser, or just check autoprefixer if you’re in Codepen).

That’s it! Play around with the blur value to get the effect you want, but there’s nothing else needed. Here’s what that gives you:

Conclusion

The downslide to using the second of these methods is the poor browser support. Right now you can expect support in Edge, and Safari, but that’s about it. Still, this frosted glass effect can be a very nice way of enhancing UIs for browsers that do support it.

Useful Links


Discover more from WIREDGORILLA

Subscribe to get the latest posts sent to your email.

Similar Posts

  • Code Snippets To Customize Jetpack

    Code Snippets To Customize Jetpack

    Automattic’s Jetpack plugin has come a long way! It’s been much-maligned in the past for being bloated and slow and for that reason many developers wouldn’t touch it with a 10-foot keyboard. These days it’s much better – it’s more truly modularized to give you more control over exactly what’s activated. From the code side of things, developers will be pleasantly surprised to discover that it has been sprinkled with lots of actions and filters. So, while Jetpack is still generally marketed to entry-level end users, there are actually some nice Easter eggs for developers who want to customize things a little bit for their clients.

    This article provides some code snippets and examples of a few ways to customize Jetpack modules.

  • How to optimize your landing pages for users

    Landing pages are a very important part of your website. And if you optimize your landing pages, you can increase both your traffic and your conversion rate. Obviously, you should tailor this page to your preferred audience, but there are a number of things that go for all landing pages. In this post, we’ll go […]

    The post How to optimize your landing pages for users appeared first on Yoast.