I recently came across an odd behaviour in Webkit browsers (under OSX at least) which took far longer to resolve than I would like!
Essentially: setting filter: blur(0)
(or the vendor-specific -webkit-filter
) on an element should mean that no form of blur is applied to the element.
However Webkit still blurs the element when either blur(0)
or zeroing with a unit specified (ie: blur(0px)
) is assigned to it.
I've knocked together a quick Fiddle here to demonstrate: http://jsfiddle.net/f9rBE/
This shows three identical divs containing text (no custom fonts):
<div class="no-blur">
<p><strong>This has absolutely nothing assigned</strong></p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam facilisis orci in quam venenatis, in tempus ipsum sagittis. Suspendisse potenti. Donec ullamcorper lacus vel odio accumsan, vel aliquam libero tempor. Praesent nec libero venenatis, ultrices arcu non, luctus quam. Morbi scelerisque sit amet turpis sit amet tincidunt. Praesent semper erat non purus pretium consequat. Aenean et iaculis turpis. Curabitur diam tellus, consectetur non massa et, commodo venenatis metus.</p>
</div>
One has no style at all assigned to it whilst the other two have blur(0)
and blur(0px)
:
.no-blur{}
.zero-px-blur{
-webkit-filter: blur(0px);
-moz-filter: blur(0px);
-o-filter: blur(0px);
-ms-filter: blur(0px);
filter: blur(0px);
}
.zero-blur{
-webkit-filter: blur(0);
-moz-filter: blur(0);
-o-filter: blur(0);
-ms-filter: blur(0);
filter: blur(0);
}
If you take a look in Safari or Chrome, the bottom two are blurred:
A few things worth noting:
- This unintentional blurring also occurs in Safari on iOS7 devices (both iPhones and iPads);
- It also occurs on Chrome and Safari under OSX;
- It doesn't appear to occur under Chrome and Safari on non-retina Apple hardware;
- It doesn't happen under FireFox in OSX.
Of course, filter: blur
isn't supported at all in Firefox just yet so it's hard to tell whether the behaviour I'm seeing is intentional/expected behaviour, or whether this is a bug in Webkit?
I eventually came to the conclusion that using blur(none)
instead had the desired effect (ie: removed all blur effects), but I'm confused as to why using zero doesn't have the same effect given that in other filter examples (eg: filter: grayscale
) can be reset simply using zero rather than the none keyword.
Why is this?