How to create a frosted glass effect using CSS?
Asked Answered
E

7

12

I'd like to create a div that is fixed in one position and make it translucent - making the contents behind it partially visible and blurred. The style I'm looking for is similar to the div of the 'See All' thumbnails in the Apple website.

The only thing I can do is adjust opacity: 0.9 but I cannot blur the contents that go under the div.

Note: The div has a fixed position and the background scrolls. The background that scolls is a mix of text and photos.

Evidential answered 13/6, 2013 at 14:40 Comment(1)
css-plus.com/2012/03/gaussian-blurImpoverish
F
23

CSS

CSS 3 has a blur filter (only webkit at the moment Nov 2014):

-webkit-filter: blur(3px); /*chrome (android), safari (ios), opera*/

IE 4-9 supports a non-standard filter

filter:progid:DXImageTransform.Microsoft.Blur(PixelRadius='3')

See some nice demo for the blur and other filters here.

webkit CSS filter blur example

For future reference here is the compatibility table for CSS filter. Firefox seems to be getting the feature in v35+ while even IE11 does not seem to have any compatibility.

SVG

An alternative is using svg (safe for basically IE9 and up):

filter: url(blur.svg#blur);

SVG:

<svg version="1.1" xmlns="http://www.w3.org/2000/svg">
   <filter id="blur">
       <feGaussianBlur stdDeviation="3" />
   </filter>
</svg> 

jsFiddle Demo

Javascript

You will achieve the highest browser compatibility with javascript, but usually the slowest performance and added complexity to your js.

Freaky answered 13/6, 2013 at 14:44 Comment(5)
That's not true. blur is a available through filter.Carmeliacarmelina
this repo is no longer update, the owner don't recommand it to use in production.Finnougrian
@martialdidit what repo? blur.js? I cannot find it on their site.Freaky
This doesn't answer the question. This shows you how to create a blurred image, not how to create a semi-translucent element whose background is blurred.Puppet
blurjs.com is a dead link nowCircinus
N
8

You can use CSS image filter.

-webkit-filter: blur(2px);
filter        : blur(2px);

More info on CSS image filters:

Demo: JSFIDDLE Blur filter exemple


But in fact, they are using pre processed JPG, and just using it as a overlay in the correct position.

#background {
    position: absolute;
    left: 10px;
    top: 10px;
    width: 600px;
    height: 600px;

    background-image: url(http://images.apple.com/home/images/osx_hero.jpg);
    background-position: 0 0;
}
#blur {
    position: absolute;
    left: 50px;
    top: 50px;
    width: 120px;
    height: 500px;

    background-image: url(http://images.apple.com/home/images/osx_hero_blur.jpg);
    background-position: -50px -50px;
}

<div id="background">
    <div id="blur"></div>
</div>

Demo: JSFIDDLE CSS blur technique

Negligence answered 13/6, 2013 at 14:54 Comment(2)
FF and IE do not support filter atm, so there is no -moz-filter : blur(5px); and -ms-filter: blur(5px); developer.mozilla.org/en-US/docs/Web/CSS/filterFreaky
My text within the div will blur too, any idea why?Contaminant
S
2

You made me want to try, so I did, check out the example here:

http://codepen.io/Edo_B/pen/cLbrt

Using:

  1. HW Accelerated CSS filters
  2. JS for class assigning and arrow key events
  3. Images CSS Clip property

That's it.

I also believe this could be done dynamically for any screen if using canvas to copy the current dom and blurring it.

Slaby answered 20/7, 2013 at 12:48 Comment(0)
V
2

This should be coming browsers in the future as a CSS filter called backdrop-filter. There's virtually no support for it at all currently. For browser support see: http://caniuse.com/#feat=css-backdrop-filter

This CSS filter will do the frosted glass without any funny business, or hacks. It'll just do it.

Someone recorded a demo of it on Vine, and it looks really good. They were using Safari nightly to get access to the CSS filter. https://vine.co/v/OxmjlxdxKxl

Vtol answered 25/7, 2015 at 15:43 Comment(0)
C
1

Just put the same image (or parts of it) with opacity .9 a few pixels left/right/up/down - voilà

Chickabiddy answered 2/5, 2014 at 17:30 Comment(0)
A
1

Some browsers support the new CSS property backdrop-filter. This property enables you to add a "frosted glass-like" effect on an element without using the pseudo classes.

Example:

element {
    background: rgba(255, 255, 255, .5);
    backdrop-filter: blur(10px);
}

https://developer.mozilla.org/en-US/docs/Web/CSS/backdrop-filter

Acidimetry answered 27/2, 2020 at 22:24 Comment(0)
C
-2

First of all the OP states that the background scrolls. None of the available answers really allow scrolling. Based on how html is set up it is impossible. But with the use of famous/angular one can have multiple rendering engines to achieve this affect. I have it constructed here.

The idea behind it is two renderings of the site. One is the header version which is blurred. The other is the body. I used Famous/Angular and use templating to render the template in the head and body. The header needs an offset for the height of the header so that things match up. I will be having actual code posted soon here and on the site.

Counterchange answered 22/4, 2015 at 22:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.