58

On many smartphones (Samsung Galaxy II being an example) when you browse through a photo gallery, its blurred copy is laid out in the background. Can this be achieved by CSS dynamically (ie. without the copy of the photo being prepared upfront saved)? Is there any kind of complex CSS image filter to blur an image?

user776686
  • 5,924
  • 9
  • 52
  • 94
  • 1
    Note that while this is possible with CSS3 'filter: blur(3px)' it is currently extremely expensive in terms of processing power. – Henrik Dec 03 '12 at 11:08
  • 1
    Here you can find all your answers! [CSS3][1] is the way! (: [1]:http://www.inserthtml.com/2012/06/css-filters/ – Luca Davanzo Dec 03 '12 at 11:06
  • My post got deleted. but here was the original link http://thenewcode.com/534/Cross-browser-Image-Blur-with-CSS – surya Sep 09 '16 at 17:26
  • [blur filter on MDN](https://developer.mozilla.org/en-US/docs/Web/CSS/filter-function/blur) – aloisdg Sep 24 '19 at 15:02

6 Answers6

45

You can use CSS3 filters. They are relatively easy to implement, though are only supported on webkit at the minute. Samsung Galaxy 2's browser should support though, as I think that's a webkit browser?

Andy
  • 13,875
  • 3
  • 46
  • 76
  • this works but unfortunately only with webkit. For now it seems that maybe the only approach is to blur an image with photoshop and place it as background if you want the same effect in each browser. – Daniel Ramirez-Escudero Apr 05 '13 at 07:27
31

With CSS3 we can easily adjust an image. But remember this does not change the image. It only displays the adjusted image.

See the following code for more details.

To make an image gray:

img {
 -webkit-filter: grayscale(100%);
}

To give a sepia look:

img {
 -webkit-filter: sepia(100%);
}

To adjust brightness:

img {
 -webkit-filter: brightness(50%);
}

To adjust contrast:

img {
 -webkit-filter: contrast(200%);
}

To Blur an image:

img {
 -webkit-filter: blur(10px);
}

You should also do it for different browser. That is include all css statements

  filter: grayscale(100%);
 -webkit-filter: grayscale(100%);
 -moz-filter: grayscale(100%);

To use multiple

 filter: blur(5px) grayscale(1);

Codepen Demo

Raj Sharma
  • 3,196
  • 3
  • 27
  • 38
11

This code is working for blur effect for all browsers.

filter: blur(10px);
-webkit-filter: blur(10px);
-moz-filter: blur(10px);
-o-filter: blur(10px);
-ms-filter: blur(10px);
sameeuor
  • 636
  • 7
  • 16
2

Yes there is using the following code will allow you to apply a blurring effect to the specified image and also it will allow you to choose the amount of blurring.

img {
  -webkit-filter: blur(10px);
    filter: blur(10px);
}
JacobG182
  • 319
  • 1
  • 6
0

CSS3 filters currently work only in webkit browsers (safari and chrome).

Dhaust
  • 5,306
  • 8
  • 50
  • 73
Aneesh
  • 255
  • 3
  • 11
0
img {
  filter: blur(var(--blur));
}
Roopendra
  • 7,221
  • 16
  • 59
  • 84
Bar Horing Amir
  • 3,302
  • 2
  • 20
  • 19