views:

42

answers:

4

Are there any common problems why alt attributes on images wont work.

Tested for IE8 Standards mode.

Thanks in adv.

+4  A: 

if you want to show text from alt attrib, use title='' attrib.

The difference:

  • alt shows up instead of img - when img cant load
  • title shows up when you mouseover the image
Dobiatowski
It is interesting how VS2010 still uses the HTML schema with img/alt attribute and warns against not having the at attribute there.
Russell
in html specs alt is required attrib, title is only optional.
Dobiatowski
@Russell, the `alt` attribute *should* be there (for e.g. visually-impaired users). It just doesn't mean the same thing as `title`.
Matthew Flaschen
Perfect. Cheers
Ash Burlaczenko
your welcome ;)
Dobiatowski
@Matthew, good point. I was thinking he was more interested in the tooltip functionality. The alt and title should both be used if you want tooltip functionality and maximise accessibility.
Russell
+1  A: 

alt means just that, an alternative for when the image isn't displayed. If you want a tooltip, use title or longdesc. Historically alt has been abused to mean this, but IE8 has finally fixed this.

Matthew Flaschen
A: 

By "not work" I'm assuming you mean that the alt text doesn't appear when you hover over the image. You'll need to use the title attribute if you always want the text to appear in all browsers:

<img src="foo.png" alt="bar" title="bar" />
Pat
+1  A: 

Yes, you should always specify the alt attribute for these reasons:

  • In case image is not found:
    • The text from alt will be shown instead
  • The alt tag is important in terms of Search Engine Optimization (SEO)
  • Accessibility reasons
Sarfraz