views:

45

answers:

1

Hello.

I'd like to know the difference between title attr of the tag "a" and alt attr of the tag img.

Also, wich should I use when I have an image inside an a? Just like in this case:

<a class="duplicar" href="#"><img src="Images/btnSegDuplicar.gif" alt ="Duplicar" width="76" height="20" /></a>

Right now, as you can see, I'm using the alt but I'm having a little issue. No matter the browser in my development server the tooltips is shown, but in my production server it is not. I tried using both of them (alt and title) and it worked, but it is kind of uggly. Why is that difference between both servers?

+7  A: 

You should always use the title attribute for tooltips. With images as well as with anchors.

The alt attribute is solely for the purpose of displaying a text when the image can not be viewed for some reason. That this text is sometimes shown as a tooltip is an incidental artifact of some implementations, and by no means a part of its specification.

David Hedlund
To be precise, it's IE's default and incorrect behavior that caused people to use `alt` for tooltips, but it's quite simply always wrong.
Joeri Hendrickx