Click here to Skip to main content
Click here to Skip to main content

PNG alpha support for Internet Explorer

, 15 Sep 2004
Rate this:
Please Sign up or sign in to vote.
An article on how to implement PNG alpha support for Internet Explorer


Internet Explorer doesn’t support the alpha channel in PNG images. However the fix is to use the "AlphaImageLoader" filter. This script replaces all PNG images on the page with a blank image (blank.gif) and adds the "AlphaImageLoader" filter with the original image source. The blank image is to avoid the "broken image" picture to display above the filter. This script also supports printing and changing the source image at runtime.


//Array containing all PNG images on the page
var PNGimageArray = new Array();
var isPrinting = false;

//Path to the blank image (1x1 transparent)
var blankSrc = "blank.gif";

//Captures print events
window.attachEvent("onbeforeprint", function () { beforePrint(); } );
window.attachEvent("onafterprint", function () { afterPrint(); } );
//Tests if element is a PNG image, and if so fixes it
function addPngImage(element){
  if (/\.png$/i.test(element.src)) {
    element.attachEvent("onpropertychange", function () 
      { propertyChanged(); } );
    PNGimageArray[PNGimageArray.length] = element;

//Applies filter and changes source to blank
function fixImage(element) {
  element.runtimeStyle.filter = 
      src='" + element.src + "')";
  element.src = blankSrc;

//If property "src" is changed fixs image (not 
//if it is changed to blank though)
function propertyChanged() {
  if (isPrinting) return;
  var element = event.srcElement;
  var pName = event.propertyName;
  if (pName != "src") return;
  if (!new RegExp(blankSrc).test(element.src))


//Turns image back to original before print (Explorer can't print filters)
function beforePrint() {
  isPrinting = true;
  var element;
  for(var i = 0; i < PNGimageArray.length; i++){
    element = PNGimageArray[i];
    element.src = element.filters[0].src;
    element.runtimeStyle.filter = "";


//Fixes image after print
function afterPrint() {
  isPrinting = false;
  var element;
  for(var i = 0; i < PNGimageArray.length; i++){
    element = PNGimageArray[i];

Style that makes all images run the addPngImage function. I use "expression" instead of "behavior" to avoid some security issues in Internet Explorer.
<style type="text/css"> img { filter:expression(addPngImage(this)); }


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Web Developer
Sweden Sweden
Software developer

Comments and Discussions

GeneralFIX for resizing images PinmemberMember 13451288-Dec-07 19:29 
QuestionWhat license? Pinmemberchappi120-Sep-06 4:55 
GeneralGreat Work But Resizing images doesnt work!!! PinmemberPier...29-Jun-06 2:28 
GeneralResource Protocol ! PinmemberNicolas MEURET13-Feb-06 23:49 
GeneralMaps PinmemberEDB_ENVC17-Jun-05 5:09 
GeneralRe: Maps Pinmembernoname987631-Jul-05 1:56 
GeneralFix for filenames with "(" or ")" PinmemberPolyVector17-Feb-05 13:03 
QuestionPNG Background images??? Pinmemberdclark11-Jan-05 15:26 
GeneralCross-Browser Compatibilty PinmemberDavy Boy29-Nov-04 12:53 
GeneralIt is a problem PinmemberSanjit Rath17-Oct-04 9:33 
GeneralBrilliant PinmemberCSnerd14-Oct-04 16:19 
GeneralRe: Brilliant PinmemberPartenon15-Oct-04 7:06 
GeneralLooks Familiar PinmemberDFU2323-Sep-04 7:59 
GeneralRe: Looks Familiar PinmemberPartenon23-Sep-04 12:43 
GeneralWell known problem PinmemberPhilippe Lhoste22-Sep-04 1:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.150224.1 | Last Updated 16 Sep 2004
Article Copyright 2004 by Magnus_
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid