Transparent PNGs (Yes, Even in IE6)

It will be a glorious day in the world of the Web when Internet Explorer 6 is completely abolished from every computer everywhere. I will not read from the litany of charges against this most sinister of Web applications; my own chief gripe has to do with how Microsoft implemented the PNG-24 format, and how their slip-shod work has held back the visual possibilities in Web design (without using Flash) for over 5 years.

The good news, even if it does come as IE6 is being phased out, is that we now have a workaround that let’s us make use of the transparency capabilities of PNG-24, if only for images used as backgrounds.The PNG-24 image format is now standard on all Web browsers, and, although it’s not as good as JPEG at compressing complex images like photographs, it is very good at compressing solid color images, even with slight effects such as gradients.

It’s greatest feature, though, is that it preserves the alpha channel of images. That is, you can have transparent areas in your image with an opacity anywhere between 0% and 100%. This not only opens great new possibilities and potentials for your designs, it can also dramatically improve your work flow and flexibility, since you only need cut only a single image against a transparent background which then gets re-used wherever you want it, against any color or pattern. You can then change background colors or images at will, and never have to re-cut the foreground images on top to accommodate the change.

In the image above, the black and white circles fade from 100% opaque to 25% on a gray background.

When the exact same image is placed on a red background the transparent circles allow some of the red through. Notice also, that the edges of the circle do not show the distinctive aliasing of GIF images that were indexed against a solid color. The catch is, though that the image you see is actually in the background of a layer, rather than in an img tag.

In this example, the three colored circles are at 50% opacity on a white background.

When the same image put on a black background, the colors are now darker.

Although PNG transparency will not work with blending modes like darken, lighten or overlay, it will work with effects like a drop shadow.

So that you can reuse an image with a drop shadow on any background you want.

To use a Transparent PNG in your Web page:

  1. Start by creating your image with transparencies in your favorite image editing program. You can set opacity anywhere between 0 and 100%. All antialiasing (transparent pixels on the edges of objects that make curves look smooth on the screen rather than jagged) are also preserved. However, if you are using blending modes, these will not be preserved. So, for example, the PNG image can not be made to invert colors underneath.
  2. Make sure that the background is set to transparent. In some image editing software like Photoshop and Fireworks, this means turning off the background layer so that you see the checkerboard pattern. In OmniGraffle, you will choose a transparent background option while saving in step 3.
  3. Save your image as a PNG-24, making sure that the Transparent option is checked. PNG-24 has a limited number of options, so there is little else you can do to optimize the image.
  4. In your HTML, you will need to provide an element into which the PNG is placed as a background. For this example, let’s set up a specific DIV with an ID. However, you can use any HTML tag. Often I’ll use a background image in an H1 tag to provide a graphic header treatment, while also placing HTML text in a span tag with a class called textOnly which I then hide using display:none so it doesn’t show up. This is a good practice for non-graphic browsers and for Search Engine Optimization.

    <div id=”transPNG”></div>

  5. In your CSS, add your transparent PNG to the element from step 4 as a background image.

    #transPNG {
    width: 100px; height: 100px;
    background: transparent url(’transparent-PNG-example.png’) 0 0 no-repeat;
    };

  6. If you view the above code in most modern-browsers, you should now see your image with whatever is behind it on the Web page showing through in transparent areas. However, if you look at it in Internet Explorer 6, you will see that the transparent areas filled with an opaque pale blue. Although IE 6 “supports” the PNG-24 format, it did not support transparency. To fix this, we will need to add a bit of special code that turns the background image being placed by the CSS off and instead places it in there using the Microsoft the alpha channel filter.

    #transPNG { width: 100px; height: 100px;

    background: transparent url(’transparent-PNG-example.png’) 0 0 no-repeat;
    _background: none;
    _filter:
    progid:DXImageTransform.Microsoft.AlphaImageLoader
    (src=’transparent-PNG-example.png’, sizingMethod=’crop’)
    }

    Use the underscore before the style to hide it from other browsers, then set the background to none, and then use the alpha filter with the same source as your background. You have two options for the sizing Method: crop and scale. Crop will only show the image once, while scale will stretch the image to fill the entire area. You cannot tile these background images.

  7. Now, viewing the image in IE6, it should look exactly the same as in other browsers.
  8. BUT WAIT! THERE’S MORE! The big draw back of using transparent PNGs in your design is that they interfere with links and form inputs in IE6. Place a link tag or form input field on-top of a transparent PNG that has had the alpha filter applied, and they will become un-clickable in the most popular browser. Fortunately, there is a simple (although inexplicable) solution: set the position type of link and form elements to relative and set the cursor type. For some reason, your links and form elements will then work as normal.

    a { _position: relative; cursor: pointer; }
    input {_position: relative; cursor: text; }

The downside is that this trick is that it can only practically be applied to background images and it can interfere with links and form elements (although there is a fix for that too). However, once you get used to it, you will find that you can use background images in place of the IMG tag in a lot of different circumstances you may never have considered.

I’ve used this technique to great effect in a lot of different Web sites, most notably Yuri’s Night 2008 where I used a non-scrolling gradient backgrounds with transparent PNGs in the module backgrounds on top, so that, as the user scrolls the page, the module backgrounds seem to shift their color. You can also place a variety of textures in the background and, with scrolling turned off, the module backgrounds can be made to look like glass chips as with another site I did, RED.

Web Typography: Interview with WOW

World Organization of Web Masters

At the recent Voices that Matter conference, I had the privilege of having dinner with Bill Cullifer, the Executive Director of WOW (World Organization of Webmasters). I hadn’t check in with that group in a while (they’ve been around since 1996), so I was excited to hear about a lot of the great stuff the are doing to help educate Web professionals, including conferences, and “Iron Chef” student competition, and certification. Bill invited me to be interviewed for the WOW Technology Minute, and we talked about Web Typography.

Check it my interview on the WOW Technology Minute Web site.

Twitter Updates for 2008-07-10

  • is worn out from showing his dad how to use WordPress. #
  • is getting ready to talk about Web Typography, but needs his dongle. #
  • is debating whether to go ahead and install iPhone OS 2 yet or not… hmmmmmmm. #
  • @Hicksdesign when dd you see it? i was n with Apple tech support all afternoon about Mobile Me. #
  • thinks the next six hours until iPhone 2.0 are going to be VERRRRY long. #

Powered by Twitter Tools.

Twitter Updates for 2008-07-09

  • mind just blew up watching the Doctor Who season finale. He is now picking up the pieces. #
  • is zeroing in in the Blake’s 7 site design. #
  • @tim846 I’m not saying nothing (but it is totally unbelievable!) #
  • talking to jay about iPhone apps for news. #

Powered by Twitter Tools.

Twitter Updates for 2008-07-08

  • got great new books in the mail. #
  • @daveartz please tranlate Edge and CM Punk. #
  • will be finishing up his books template today, and then on to writing. #

Powered by Twitter Tools.

Twitter Updates for 2008-07-07

  • enjoyed a rousing book club discussion, even though he didn’t read the book. #
  • is finishing his daughter’s dresser #

Powered by Twitter Tools.

Twitter Updates for 2008-07-06

  • Is working on a site while watching a Doctor who with his son (who keeps his fingers in his ears). #
  • thinks his wife is far more gracious and forgiving than he will ever have a day to. #
  • NO SPOILERS!!!!@kplawver I haven’t gotten the last episode yet! #
  • helping my daughter build her new dresser. #

Powered by Twitter Tools.

Twitter Updates for 2008-07-05

  • is getting moved in #

Powered by Twitter Tools.

Twitter Updates for 2008-07-03

  • thinks it’s horribly rude to leave the auditorium before the bad leaves the stage. #
  • thinks it’s horribly rude to leave the auditorium before the band leaves the stage. #
  • loves “London, England” by Corduroy, but thinks that in the 21st Century he should be able to get it electronically (legally). #
  • thinks it’s fascinating that 4 different people pointed out that, despite being late to a W3C meeting, he had time to update his status. #
  • getting ready to watch Doctor Who with the kiddies. The Unicorn and the Wasp! #

Powered by Twitter Tools.

Browser Safe Fonts: Beta Available!

Web typography is pretty much synonymous with limitations. Limited controls, limited styles, but, most importantly, limited font-family choices. The first two limitations can only be overcome through changes in the browsers, however, there are a surprisingly large number of fonts to choose from, if you are willing to work with a more fluid typography.Most designers are familiar with the 11 “Core Web Fonts” that are industry standards. Primarily, we will use Arial (or Helvetica), Times New Roman (or just Times), and Georgia, which has become increasingly popular in the last few years. You will occasionally see Verdana and Trebuchet MS tried, but these are not the most elegant looking of fonts. We use these fonts because we know that they are pre-installed on most computers. Yet most computers will also have many other fonts pre-installed on them, either by the operating system or by specific applications.

I have created a list of “Web Safe Fonts” showing fonts pre-installed on Windows and Mac as well as fonts installed by iLife on the Mac (which is standard on all Macs) and Microsoft Office for both Mac and PC. Although not all of these fonts will be of general use, it does balloon the list of reliable fonts from 11 to around 200. To make selection easier, I have also indicated which OS the font is pre-installed for, ranked each font on a scale from 1 to 5 (with 1 for fonts certain to be installed and 5 for fonts unlikely to be installed), and the source of the fonts instillation.When choosing fonts to use, in your font-family list, keep these points in mind:

  • Test the different fonts in different combinations.
  • For headline copy, use fonts with similar widths and kerning.
  • For body copy, select fonts with bold, italic, and bold/italic versions.
  • If you download a font or use a Web Safe Font, always include a Core Web Font and generic font-family as back-ups.

View the Web Safe Fonts >>