Demo:

REGULAR IMAGE TAG

BACKGROUND IMAGE

GIF | PNG 1 | PNG 2 | None

BACKGROUND POSITION

Position A | Position B

IMAGE DROPSHADOW

(PNG background behind GIF/JPEG)

What is it?

This is a IE5.5+ "bevhavior" that automatically adds near-native PNG support to MSIE 5.5 and 6.0 without any changes to the HTML document itself. Supported features include:

How To Use

Follow these simple steps to add this to your page:

  1. Copy and paste iepngfix.htc and blank.gif into your website folder.
  2. Copy and paste this into your website's CSS or HTML:
    <style type="text/css">
    img, div { behavior: url(iepngfix.htc) };
    </style>
    That CSS selector must include the tags/elements on which you want PNG support -- basically, give it a comma-separated list of tags you use. It must also include the correct path to the .HTC relative to the HTML document location (not relative to the CSS document!). For instance, yours may look like this:
    <style type="text/css">
    img, div, a, input { behavior: url(/css/resources/iepngfix.htc) };
    </style>
  3. If your site uses subfolders, open the .HTC file in a text editor like Windows Notepad and change the blankImg variable to include a correct path to blank.gif like so:
    var blankImg = '/images/blank.gif';
    Again the path is relative to the HTML file. Otherwise, you will see a "broken image" graphic!
  4. Sit back and enjoy! Perhaps consider making a donation to support this script's development if you like what you see :). Alternatively I would certainly appreciate a crediting link on your site back to mine!

If you are interested in more details or an alternative activation method for the script that maintains CSS validation compatibility, see the source code to this demonstration file.

How to fix common problems

I've pasted in the CSS but my PNGs aren't transparent!
Make sure you remember that the path to the HTC file is relative to the HTML file, not the CSS file (like CSS background images are).
It works offline but not online.
First try unzipping this default demonstration and uploading to your web server as-is. If it doesn't work, you have a MIME type problem. You must ensure your server is sending the correct MIME type of "text/x-component" for .HTC files. Try one of these two easy fixes:
  1. Upload the ".htaccess" file from within this script's download ZIP to your webserver, which will make Apache send the correct MIME type.
  2. Instead of calling "IEPNGFIX.HTC" from your CSS, upload IEPNGFIX.PHP to the same folder and call that instead, which also sends the right MIME type.
My PNGs are transparent but have a funny border or red "X" icon.
Check that the blankImg variable is set correctly in the .HTC file, again this should be relative to the HTML document containing the PNGs.

Limitations and known isses with the script

License:

IE5.5+ PNG Alpha Fix v1.0RC5

(c) 2004-2007 Angus Turnbull http://www.twinhelix.com

This is licensed under the GNU LGPL, version 2.1 or later.

If you want to link my site or make a donation, you're more than welcome :).

Tech Specs

IE5.5+ includes support for a DirectX AlphaImageLoader filter, that can take an element on the page and insert a correctly-rendered PNG image inbetween the element's content and background. This script automatically scans all IMG SRCs and element backgroundImages for .PNG files, and if it finds them, it removes the regular image and substitutes this filter in place. See the source if you want, but I've coded it quite compactly to keep download time down to a minimum (at the expense of comprehensibility, sorry!).

Changelog