CSS PNG Hack For Internet Explorer (IE)

It’s been a problem for many developers. How do you create a transparent image for Internet Explorer 6 using a PNG. As you are all probably aware IE 6 does not support transparent PNGs but don’t panic there is a solution.

The Solution

This is by no means new; however, I thought it was worth while posting. By using Alpha filters designed specifically for IE we can force Internet Explorer to behave as expected.  As shown using the code laid out below:

The Code

The CSS source is as below.  The first class defines the Alpha filter applied to the containing DIV and also sets a height and width (This has to be the same as the PNGs height and width).

The second class simply hides the original PNG from all versions of Internet Explorer 6 and below.  This is applied as we do not want Internet Explorer to see the PNG twice with the non-transparent version still showing.

.ie-png {
_filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=’imagename.png’,sizingMethod=’scale’);
height: 50px;
width: 257px;
}


.ie-hide{
border:0px solid #FFFFFF;
_display:none;
}

The HTML is also very simple.  Simply add the PNG and wrap it with a containing DIV using the classes as shown below.

<div class=”ie-png”>
<img src=”yourimagename.png” class=”ie-hide” alt=”freshtuts is a life saver” title=”freshtuts.com is full of tutorials for webmasters” />
</div>


About Bulent

Yes, my name is Bulent. I am originally from Turkey but now reside in United Kingdom. I have been working as a designer for over 8 years and have been very fortunate to have worked on a wide variety of projects. I have recently developed one of the most succesfull recruitment portal for nearly a million Turkish speaking community in UK within few months we had reached to nearly 65,000 users and stil growing. Thank you for stopping by!

Leave a comment

You must be logged in to post a comment.