Skip to content

Cool cross-browser styling with CSS and IE’s filter

A few new and cool CSS3 styles become realistic options when building a website if you combine them with IE’s filter.

View demo

A few new and cool CSS3 styles become realistic options if you are designing website. That is: as long as you combine them with IE’s counterpart filter.

The list of things that Safari, Chrome and Firefox support is getting larger and larger. Not all functionality is that interesting since we still have to make sure that IE users receive a functional site. And if you’re building something for a customer, you have to make sure that the website looks like what the customer expects it to look like. Most of the time that means that the website must be more or less an exact copy of the designs in Photoshop.

But what is easily forgotten is that for years Internet Explorer sort of supports some CSS styles through the proprietary filter property. I mostly use filter for setting opacity or forcing alpha channels in a PNG24, but when I saw a text shadow in a website I realized that IE can do that trick already for years. So I came up with this list of things that should work on almost any browser:

  • Text shadow
  • Box shadow
  • Blur
  • Gradient background
  • Opacity
  • PNG24 alpha

A little on browser support

A little warning about the “works in”-lines you’ll seewith each example. I didn’t dig very deep to see which version of Opera started to support text-shadow. If see in a support chart that Opera 9.62 supports text-shadow, I haven’t dug deeper to if it was also supported in Opera 9.61. Especially when I relate it to the small share of people who use that browser. If you can point a source that speaks of an earlier version, I’m more than happy to correct the article.

Things you can do with CSS and filters combined

Text shadow

Works in IE 5.5+, Firefox 3.1b+, Safari 3+, Chrome 2+ and Opera 9.62+
Used sparingly can create a nice subtle effect and is a great way to make something a bit more stylish. Watch out with loss of anti-alias. More on that issue at the end of the article.

Text-shadow in IE8

Text-shadow in IE8

Text-shadow in Firefox 3.5.5

Text-shadow in Firefox 3.5.5

.textShadow {
	width: 250px;
	text-shadow: 1px 1px 1px #cccccc; /* CSS3-compatible browsers */
	filter: dropshadow(color=#cccccc, offx=1, offy=1) /* IE */
}

Blur

Works in IE 5.5+, Firefox 3.1b+, Safari 3+, Chrome 2+ and Opera 9.62+
This one is a bit of hack: CSS3’s text-shadow is misused to create a blur. It was a trick I saw on www.css-tricks.com (hence the name, I guess). And although you can see the differences between the two screenshots, both are definitely blurs. A conditional comment was used to make the text in IE a bit darker so it would match with other browsers.

Blur in IE8

Blur in IE8

Blur in Firefox 3.5.5

Blur in Firefox 3.5.5

.blur {
	width: 250px;
	color: #ddd;
	text-shadow: 0 0 2px #aaaaaa;
	text-shadow: 0 0 4px #aaaaaa;
	text-shadow: 0 0 6px #aaaaaa;
	filter:
		progid:DXImageTransform.Microsoft.MotionBlur(strength=1,direction=310)
		progid:DXImageTransform.Microsoft.Blur(pixelradius=2);
}
<!--[if IE]>
	<style type="text/css">
		/* This style is for IE browsers only by
		   using IE's Conditional Comments */
		.blur {
			color: #aaaaaa;
		}
	</style>
<![endif]-->

Opacity

Works in IE 5.5+ and in all major browsers for years and is safe to use
Definitely the most used combination of CSS and IE’s filter. I mostly use it to make the website almost invisible in favor of an absolute placed div which floats like popup window on top of the greyed out website.

Opacity 0.5 in IE8

Opacity 0.5 in IE8

Opacity 0.5 in Firefox 3.5.5

Opacity 0.5 in Firefox 3.5.5

.opacity {
	width: 250px;
	opacity: 0.5;
	-ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=50)";/*IE8+*/
	filter: alpha(opacity=50); /* IE7 and lower */
}

Gradient

Works in IE 5.5+, Firefox 3.6+, Safari4, Chrome 3+
The soon to be released Firefox 3.6 supports gradient background. Safari and Chrome already supports that cool CSS3 feature. Although you can do more with CSS3’s background gradient than IE’s filter, there’s nothing to stop you from using a simple gradient. Well, poor browser support may stop you. Firefox 3.6 still has to be released and Opera does not seem to support gradients at all.

So the browser support for gradients is less than desirable. But since all major browsers except Opera now supports gradients in their latest versions, it will become a useful styling tool soon.

Background gradient in IE8

Background gradient in IE8

Background gradient in Chrome 3.0

Background gradient in Chrome 3.0

.gradient {
	background: -moz-linear-gradient(top, bottom,from(#cccccc),to(#888888));
	background: -webkit-gradient(linear, left top, left bottom, from(#cccccc), to(#888888)) no-repeat;
	background; -o-gradient(top, bottom,from(#cccccc),to(#888888));
	-ms-filter: "progid:DXImageTransform.Microsoft.gradient (GradientType=0, startColorstr=#ffcccccc, endColorstr=#ff888888)"; /* IE8+ */
	filter: progid:DXImageTransform.Microsoft.gradient (GradientType=0, startColorstr=#ffcccccc, endColorstr=#ff888888); /* IE7 and lower */
}

Box shadow

Works in IE 5.5+, Firefox 3.6+, Safari 3, Chrome 1
If you look at the screenshots below you see a striking difference in what is called a “Shadow“. IE’s box shadow looks more like the right and bottom side of a 3D object than a real life shadow. CSS3’s box-shadow provides a shadow that’s much more realistic.

Box shadow in IE8Box shadow in Firefox 3.5.5

.boxShadow {
	-moz-box-shadow: 5px 5px 5px #888;
	-webkit-box-shadow: 5px 5px 5px #888;
	-ms-filter: "progid:DXImageTransform.Microsoft.Shadow(color=#888888,direction=125,strength=5)"; /* IE8+ */
	filter: progid:DXImageTransform.Microsoft.Shadow(color=#888888,direction=125,strength=5); /* IE7 and lower */
	background: #cccccc;
}

Use alpha channel in PNG24 images

Not really a CSS feature, neither something that lacks in modern IE browsers. But it is dearly missed in IE6. The only way to use alpha channels in IE6 (although many have found different ways apply it) is by using the filter’s AlphaImageLoader. Although this filter can save the day, it has many bugs you need to be aware of:

  • It can only be used as a background image.
  • You cannot position it like a normal background image, nor can the image repeat itself on the x or y axis.
  • Links or form elements inside a box with a transparent PNG24 are not clickable. You have to make sure that such elements have a parent that has position: relative.
  • Having lots of relative positioned elements scattered around can add extra complexity to your website if it has absolute positioned items floating on top of each other as well.
  • You’ll lose text anti-alias.

This technique is only needed in IE6. Other modern browsers use the alpha channel as it ought to be.

.imageAlpha {
	display: block;
	width: 250px;
	height: 40px;
	padding: 5px 10px;
	background: #aaf url(alpha.png) 0 0 repeat-x; /* PNG24 image with alpha layer that works in all modern browsers */
}
* html .imageAlpha { /* these styles are only picked up by IE6 */
	background-image: none;
	filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='alpha.png', sizingMethod='scale')
}

Filter bugs

Filter can clear Cleartype

The main drawback of using IE’s filter is that in some cases the element that has a filter style in IE, will lose it’s anti-aliasing. That may not sound like a big deal, because we have lived for a long time without Microsoft’s Cleartype, but it can get real ugly with larger fonts as you can see in the screenshots below. If you use a filter and it does remove the Cleartype, it’s best to keep the font-size 16 pixels or lower.

IE filters in Arial 16pxIE filters in Georgia 19px

Filters can only be applied to boxes

Filters can only be applied to block elements like div or p and they need a width or height. If not, the filter won’t work. The exception to the rule is IE8, which can show filter effects without a width or height.

View demo

Bookmark and Share
15 Responses
Follow responses to this entry through this RSS.
  1. senshikaze

    so… i need to bend over ass-backwards to make ie look like a real browser?
    nice.
    How bout people upgrade off of “my first browser” and onto a real one?

  2. R Hampton

    I’m getting a strange problem in IE7 but not IE6. The shadow filter renders my white text with a thin dark outline on letters like “O” ). I’ve tried turning ClearType on and off within IE7 but I can’t see a difference. Is it a problem with just my browser or with all IE7 browsers?

    FYI – I have a DIV with background-color:#bee48a; inside that is an unordered list containing A HREF tags with color: #fff; text-transform: uppercase; text-decoration: none; text-shadow: #693 0.1em 0.1em 0.2em; filter: progid:DXImageTransform.Microsoft.Shadow(color=’#669933′, direction=135, strength=2);

  3. Wouter Bos

    Hi,

    I did a quick test in IE8 and I have the same problem. The only solution I see is keeping the font-size at 16px or lower. And don’t use font-weight: bold either, since that seems to trigger the bug too. Than you shouldn’t have any problem.

  4. Chrissteven81

    senshikaze- You are bending over backwards for other browsers IE has very nice ways of doing it far more clean. more like we are bending over backwards for other browsers lol.

  5. Ali

    IMPORTANT::
    To solve the problem of fuzzy text in IE when using a filter, wrap the content of filtered element and set it’s position style to relative.
    EXAMPLE:

    CONTENT

  6. Jabes88

    I’m not sure what this is .. but it contains a syntax error.
    “background; -o-gradient(top, bottom,from(#cccccc),to(#888888));”
    Also I’ve found another opacity solution that I’m pretty fond of. You can view it here: http://snipplr.com/view/28205/cross-browser-css-opacity/

  7. Wouter Bos

    I think you have to replace background; ... ; with background: ... ;
    The best thing is to auto generate such CSS3 stuff:
    http://www.css3generator.com/
    http://css3please.com/

  8. fewa

    @Chrissteven81: It’s just that IE doesn’t follow any standards. Usually when we develop website layouts for applications, we first make them work with Firefox, Opera, Chrome and Safari.

    IE comes later if we have time, because making layouts look nice on it takes more time because of all the “IE-only” tricks it requires. After seven years into this business, I have yet to see any benefit in NOT following the standard. These IE-only things don’t provide any more possibilities than the standard ones.

    However, of course we understand that many people still use IE and that’s why we have to take the time to provide support for our web applications that are being used in IE.

  9. isak

    It seems you have figured out how to make your text appear anti-aliased on an opaque background. How???

  10. Wouter Bos

    That’s what happens if you use a filter. Very annoying actually, because you get different aliasing in the same page. On top of it: text rendering can get really ugly when implementing custom fonts with CSS3 font-face. But if you don’t want anti-aliasing, you could force it by applying the following filter to the body-tag:

    -ms-filter: “progid:DXImageTransform.Microsoft.gradient (GradientType=0, startColorstr=#ffffffff, endColorstr=#ffffffff)”; /* IE8+ */
    filter: progid:DXImageTransform.Microsoft.gradient (GradientType=0, startColorstr=#ffffffff, endColorstr=#ffffffff); /* IE7 and lower */

    This will disable the default anti-aliasing.

  11. isak

    How are you placing your text on top so it stays black but your content box expands/contracts to allow more/less text?

  12. Wouter Bos

    I don’t know exactly what you are referring to, but I guess you want to know how the columns of the website itself are styled.

    i use this background color: “background-color: rgba(255, 255, 255, 0.8)”, the last value is an alpha value. It’s not supported by IE yet, but all other major browsers support it.

  13. isak

    I think you answered my question. It just took a bit to sink in. I was trying to make it work in IE.
    Many thanks.

  14. φωτοβολταικα

    To solve the problem of fuzzy text in IE when using a filter, wrap the content of filtered element and set it’s position style to relative

  15. jawance

    a good view testing solution.
    you do a better thing.

Leave a response