Skip to content


PNG Transparency in Internet Explorer

code.gifI teach a Multimedia class at Plymouth State University. This week we were discussing the pros and cons on the use of PNGs. I mentioned that Internet Explorer versions 6 and lower fail to render the transparency of a PNG properly, placing white background in the transparency’s place. I also took the time to plug Firefox, mentioning that Firefox does it right!

Well, one of my students, Brendan Emery sent along this fix for PNG transparency in Internet Explorer, thus refuting my biggest con on PNG use! (honestly, I can’t think of any other cons)

[This is] a JavaScript-based PNG fix for Internet Explorer 5.5 and 6 on Windows. The fix allows IE to properly render PNG alpha transparency. [...]

Why only versions 5.5 & 6? Because Windows IE versions prior to 5.5 do not support the filter which fixes the PNG problem, and version 7 (not yet released at the time of writing in January 2006) is reported to have fixed the issue entirely.

The code can be used either by a one-time copy-and-paste or as an include file. The entire thing is completely ignored by all other browsers – in fact it is treated as an HTML comment – thanks to IE’s conditional comments. This solution is therefore light, portable and non-invasive to other browsers.

Posted in Blog, Technology.

Tagged with , , , , , .


16 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.

  1. Death_Tap says

    You got pwned.

    Don’t fail me!

  2. SEO Articles says

    These Javascript fixes aren’t exactly ideal – and most solutions only fix img tags, not background pngs.
    Bah, wish we could just ignore IE.

  3. TerrorBite says

    …since when did backgrounds need transparency?

    It’s not like there’s anything behind a background.

    In that case, just convert to a non-transparent PNG.

    Also, it’s not all transparent PNGs that are affected – only the ones with alpha transparency. The ones with index transparency (like transparent GIFs) are fine. Which sucks.

  4. Trevor says

    TerrorBite:

    Background images need transparency when they are applied to elements intended to be viewed on top of (in the z-index) another element, or another background, or whatever. I can think of a million different ways to use that.

  5. Suj says

    Terrorbite, you talk rubbish :) If you have a container dv with a background image, then another over the top – with a transparent png background, you’ll have a nice opaque effect, uncovering slightly what’s beneath (the picture).

    Thats why background images could make use of transparency.

  6. JD says

    As a deisgner I wish that IE could be removed from every computer and replaced with Firefox. How come everyone else even open source handle PNG, but IE can’t find the time to fix it over the last 6 years.

  7. SeoBlog says

    Интересная статья ‘PNG-прозрачность в IE 5.5-6′: http://www.tigir.com/alpha_png.htm

  8. Florin says

    Hi,

    Good fix, but how can I change it to support background png’s? I don’t need background-position or repeat-x(y), just


    experimentation revealed I could traverse the Stylesheets collection and use the AlphaImageLoader trick to replace all background-image attributes containing PNGs

  9. stevo says

    A very nice workaround. Thanks a lot

  10. Andrew says

    I have this working but the final output is still looking different in IE6. Despite me setting a width and height in the img style it looks bigger in IE6 and doesn’t look as crisp as it does in Firefox/IE7.

    Microsoft can go to hell!

  11. CW says

    I had the same result as Andrew, basically the “fix” could not be used because it distorts images.

  12. ogłoszenia says

    Thanks a lot for this workaround!

  13. Nero says

    It doesn’t work for me. I need a transparent background which I set using CSS. Stupid IE.

  14. alec says

    Thank you so much for this fix. It saved me sooo much time.

  15. aqua says

    @TerrorBite

    That’s why no one should hire you. You don’t know sh*t.

  16. Andre Ferreira says

    The JS your student sent you, does a simple loop on the images that exist on the website and manipulates them adding the CSS properties required to atchive the goal. The JavaScript it self can be disabled! The script is nice if you are short in time, but not professional. Also has other people already sayed, it doesn’t account for background images, nor does it solve CSS background-images (neigher does it go to external CSS files).
    At the end of the day, the best solutions is still to add the required CSS manually and test it.



Some HTML is OK

or, reply to this post via trackback.