0

I understand the purpose of the title and alt attributes, but I just do not understand if I can use the same title and alt on one element.

  • The title attribute is a global attribute, which means that you can use it on all elements. It represents advisory information. You can not relay on it.
  • The alt attribute can only be used on some element. For the img element it a fallback, if you can not see the image for some reasons.

Someone told me, it causes an accesibility error, if you use the same text string for the title attribute and the alt attribute on one element (edit: if the element is an image). Is this correct? I cant find this rule any where.

astridx
  • 6,581
  • 4
  • 17
  • 35

1 Answers1

2

Now as we are talking about the title attribute and the alt attribute we must be talking about images.

Where the problem lies is that screen readers may read the title and the alt description together.

It isn't a rule directly, but this goes against best practice as you are introducing unnecessary noise / repetition.

If you want to add additional information to an element then that is what figcaption etc. are for. Don't use the title attribute.

GrahamTheDev
  • 22,724
  • 2
  • 32
  • 64
  • Thank you very much for your answer. So it is no rule there and that is why my tools do not find this and mark it as error. But it is not best practice. Is this correct or is there a rule for this? – astridx Jul 10 '20 at 09:00
  • 1
    There is no violation if that is what you mean. i.e. if you are going for VPAT this will not be a fail. It is purely a best practice but an important one on an image heavy site. If you want a tooltip of some description I have an older answer that shows how to make a hoverable overlay that works with a keyboard here -> https://stackoverflow.com/a/60581000/2702894 – GrahamTheDev Jul 10 '20 at 09:04