Sunday, 8 March 2009

Icons and image replacment

Generally speaking i'm not a fan of image replacement, but for inline icons it seems to work a treat. We had this issue that users with screen readers where struggling with our icons that we use liberally in our pages. For example, the "More information" icons that we use on some links to indicate that there is more detailed information available, looks something like this.

Image of an internet link with an icon

HTML view of anchor link code, containing an img tag

Although this looks quite reasonable it was causing problems for screen readers as they list out all images which means the user will get a list of images all saying "More information" (so a bit like having a list of links all saying "Read more..."). This is a problem with using images as text (an icon is really short hand text) if you look at them out of context they don't make sense.

Using image replacement as a way of hiding images from screen readers works quite well, as they are background images and not img tags. If we look at the same link using image replacement...


HTML view of anchor link code, containg image replacement code


I tend to use nested spans for image replacment, you may prefer to use a single span with a combination of overflow hidden and a text-indent value, depends what browser support your after. If you don't need backwards compatibility you could just use the CSS "content" property instead.

2 comments:

  1. Something like that, I would just have as a style on the link itself, giving it a background image - to me, that looks like decoration!

    or does the icon have a different function from the rest of the link?

    ReplyDelete
  2. Updated the cropped images of HTML so you can see better what's going on here. This would be used where the icon is telling the user something useful and is necessary on the link to distinguish it from other similar links. (in the above example we have multiple links e.g. [page name] more information, [page name] referral etc... which are differentiated with icons so the icon is very important )

    ReplyDelete

 

Note: the opinions on this page don't represent that of my employer in anyway. And, actually only vaguely represent my opinions on the date of publication. (Unlike Ms T, I am very much for turning)