Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is a 'title' attribute relevant in a <img> tag?

I wanted to know if adding a 'title' attribute is semantic relevant on a 'img' tag. I already always use the 'alt' attribute to respec the W3C spec.
And if yes, is the content on the 'title' attribute have to be different from the 'alt' one ?

like image 458
Sarcadass Avatar asked Sep 06 '25 17:09

Sarcadass


2 Answers

The title attribute can be used as semantic, i.e. as relating to meaning. As such, it is defined to be an advisory title, and browsers may make its value optionally available to users, e.g. as a tooltip on mouseover or as a cue spoken by a speech browser. This means that it can be used for a multitude of purposes, semantic or other. It is up to you to decide whether you use it to describe the meaning of the image, or to give authorship information, or e.g. just to show a name for the image (the name may or may not describe the meaning).

Search engines may treat the title text as relating to the image, possibly causing a page to appear in image searches when words appearing in that text are used. The details of such processing have not been disclosed and probably vary from one search engine to another.

There is no reason why the value of the title attribute should not be the same as the value of the alt attribute. They have different purposes, but sometimes the same text can serve both. For example, if the image contains a person’s signature, the alt attribute should probably contain just the name in the signature, and the title attribute could contain the same (e.g., to help people who can see the image but cannot read the name easily), or it could be more explanatory, e.g. title="Joe Q. Public (signature)".

like image 175
Jukka K. Korpela Avatar answered Sep 11 '25 08:09

Jukka K. Korpela


Just to expand a little about what @SLaks said in their answer. The title attribute can also help with SEO and expressing more about what a web page has to offer. Just a tid bit to add is all.

like image 32
Nomad101 Avatar answered Sep 11 '25 09:09

Nomad101