The alt attribute is NOT for tooltips
I’m am so tired of the never-ending misunderstanding of the
alt attribute versus the
IE’s harm on the world
Internet Explorer up to version 7 incorrectly displays the value of the
alt attribute as a tooltip when you hover an image. This has led to numerous web developers thinking that
alt is supposed to be used for tooltips, and has in turn led to customers, managers et al believing so too, hence incorrectly using the term for when they want a tooltip displayed.
There are still hundreds of thousands of web pages out there built on that the
alt attribute will act as the tooltip. These will only work in Internet Explorer, not in Firefox, Safari, Opera or any other web browser.
alt attribute – how it should be
Start by reading the W3C specification:
Several non-textual elements (IMG, AREA, APPLET, and INPUT) let authors specify alternate text to serve as content when the element cannot be rendered normally.
The name of the attribute,
alt, is short for alternate. That means it should be display if the image fails to load, not otherwise.
The true tooltip attribute –
If you want do display a tooltip, you should instead use the
title attribute. That will work for basically any element in a web page, too, not just image elements.
Microsoft has backed down
With Internet Explorer 8, Microsoft has finally backed down, acknowledged this as a bug, and fixed it. So for anyone depending on the
alt attribute, you need to reconsider, since that will not even work in IE 8.
The difference, once again
alt attribute is there as an alternative to the image.
Tooltips, via the
title attribute, is there to complement what you see.
Got it? Please, please say yes!
The problem is that without DOM prototypes and other standard features it is truly difficult to fallback with compatibility (IE5 to 7)
An unobtrusive but expensive workaround could be something like:
for(var a = document.getElementsByTagName("a"), i = 0, length = a.length; i < length; ++i)
if(!a[i].alt && a[i].title)
a[i].alt && a[i].title;
but again, adding stuff like this to IE will simply mean to make the slowest browser even slower so I do not agree that much about these kind of workarounds. In few words, we cannot fix IE backward, it is better to go on and let user update their browsers, imo.
sorry, this after the if …
<code>a[i].alt = a[i].title;</code>
Nice that they've finally fixed it.
@Andrea – But your fix would turn all the title-attributes into alt-attributes if I'm not mistaken – how would that fix it? The problem isn't that IE _doesn't_ display title-attributes, it's that it _does_ display alt-attributes.
Also, I think that code should be running on img-elements rather than a-elements, but I guess that's just a typo.
I suppose instead just removing all the alt-attributes in IE would "solve" it, but I for one can't be arsed to put in workarounds for that browser anymore…
@Andreas, that is a fallback for users expecting tooltips over links or images (as you spotted) … which means we write W3 code but IE6 or 7 users will still read the tooltip.
It does not matter if it is an IE error, they expect the tooltip over the link. So, accordingly, I am more for "no more tooltips? just change browser" rather than "impossible or expensive" fixes. got my point?
Been saying it for years, myself.
I am sure it's going to come back to haunt me, but I think that with IE8 maybe Microsoft has finally seen the light and in a few years, the web will be a nicer place.
It shouldn't be too hard for Microsoft to update IE7 and IE6 with this behaviour as well, but I guess that'll never happen … EVEN if they admit it being a bug.
Great post Robert!
Another thing regarding the title-attribute is the "Supplementing link text with the title attribute"-issue. That's when the same text appears in the link text and the title attribute. A very annoying thing I see quite often.
Dude, you're preaching to the choir! 🙂
I thought you'd agree. 🙂
Yeah, I've seen some people using <code>alt</code> attributes on links, believeing it will be a tooltip. Hiwever I agree with the stance that if you have, you have to fix the code – no extra script to cover up for that.
Oh, man, that will haunt you! 🙂
Great point! That surely has to be stopped too, and most commonly I see that as part of the core of some CMSs. Horrendous!
Yeah, yeah, I know… 🙂
Wow — I had thought they'd never get that one fixed.
Yeah, me neither. 🙂
The ALT attribute, also wrongly used as stated, is actually very useful on AREA, IMG and INPUT elements. It is part of the specs.
It should aid textual UA to render alternate content and so said, to have a mean to reach visual impaired users with speech etc…(and for the other uses you already mentioned, less important).
We don't have to ditch useful things having a real scope, we need to ditch our habit to use whatever comes easy in a wrong but seemingly useful way, it will not last long !
Oh, absolutely! The <code>alt</code> attribute is indeed useful, as long as it is used the way it is meant to be.
[…] Je vous propose ici une traduction de l’article de Robert Nyman, sur la mauvaise utilisation de l’attribut html ALT. Pour les amoureux de la langue de Shakespeare, l’article original est ici. […]
If you're not checking your website for functionality with images disabled, you aren't even TRYING for accessibility, and may as well admit that it's of no concern to you and your employer.
I noticed that image tooltips were missing in IE8 and Firefox for all web pages I had designed. I then realised I had only specified alt attributes instead of title attributes!
Having a portfolio of hundreds of Web pages I was faced with the time-consuming task of adding title attributes to applicable images. Thankfully I stumbled upon a Windows application called Alt&Title that did this tiresome task for me!
Instead of spending hours manually adding title attributes, Alt&Title did it for me in minutes.
Give it a go. I hope you find it as useful as I have!
Here is the web page promoting it…
Nice, thanks for the tip!
What is wrong in displaying ALT content as tooltip if there is no TITLE attribute? Instead of thinking about ‘stick with syntax’ think about ‘usability’
Because it’s not the same thing. The value in the ALT content is supposed to be alternative, i.e. what you would say to describe the image if you can’t see it, whereas TITLE is complementary.