Digital Phantasy
Digital Phantasy

Render transparent PNGs in IE!

Posted Tuesday, October 10th 2006

NOTE: This hack only works in Internet Explorer 5.5 and newer. Older browsers will continue to display PNGs incorrectly.

Every single web designer out there has moved on to PNGs for the flexibility they offer. One of the most important features ofPNGs is transparency - it allows a designer to have nice effects on their designs - however, IE never could render PNGs correctly. It doesn’t render their colors correctly to begin with, and transparency is just a myth. This is due to the nature of the IE image rendering engine.

However, there is a workaround. The Windows image rendering engine deals with PNGs and alpha channels much better, and there is a way to force IE to use this engine instead of the one built-in. This is quite a hack, but is very efficient and seems to work without any problems.

There are a few items that are needed. One is the pngbehavior.htc file. You can grab that here.
Save that file in the root of your website. Then, open up your CSS file and add this to it:

img {
behavior: url("pngbehavior.htc");
}

You also need a 1×1 pixel transparent GIF image. One is available here. Upload that to the root of your website as well.

And that’s it. All you have to do now is make sure that you have a width and height attribute set for all your images, because the windows rendering engine does not know how to render images in a browser, and has to be told the actual height and width of an image. The script that forces IE to use the engine does this by reading the width and height attributes.

And presto! Transparent PNGs in Internet Explorer!

One Response to “Render transparent PNGs in IE!”
SashoMighty Says:

Fala druze!

Leave a Reply
XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>


October 2006
M T W T F S S
« Sep   Nov »
 1
2345678
9101112131415
16171819202122
23242526272829
3031  

Quick Links:
Speedworks
UGoto
random_monkey
Camarogeddon
CTRL-ALT-DEL
Viper007Bond
Final Gear
Real Life
Penny Arcade
Kaboon
VG Cats
Sinfest
Woona (MK)
ref (MK)
TechZ
Driven To Destruction



Add Digital Phantasy to Technorati Favorites!

Trillian!

Get Firefox!

Get Thunderbird!

Eliminate DRM!

Subscribe to my RSS feed!
We are Anonymous!
Zero Punctuation


digitalPhantasy © 2005 | Sprocket by Camarogeddon
Not a sausage. Nothing you can eat, chew or throw rocks at.