Image title attribute or anchor title attribute or both?
Asked Answered
R

2

2

Let's say I have a list of images on the page, that are wrapped within links. So when u click an image it gets you to a page that displays the larger image

How should I handle title tags here?

Do I put the image title on both the image and the link, or just the image? Does it matter if the title is the same as the "alt" attribute?

<a title="image description" href="#"><img title="image description" alt="image description" src="image.jpg"></a>
Receptor answered 3/11, 2013 at 17:45 Comment(0)
S
3

HTML5 defines guidelines for alt usage. See the section "A link or button containing nothing but an image":

When an a element that is a hyperlink, or a button element, has no text content but contains one or more images, include text in the alt attribute(s) that together convey the purpose of the link or button.

So your alt attribute content could include something like "Open larger version of …".

(You may also be interested in my answer to the question on UX SE: What should the ALT text be for an image that is also a link?)


You should never have the same content for alt and title. See the general guidelines (from the W3C Candidate Recommendation of HTML5) (Update: In the W3C Recommendation of HTML5, this section got changed, and it no longer contains that quote.):

A corollary to this is that the alt attribute's value should never contain text that could be considered the image's caption, title, or legend. It is supposed to contain replacement text that could be used by users instead of the image; it is not meant to supplement the image. The title attribute can be used for supplemental information.

Sacramentalism answered 4/11, 2013 at 20:21 Comment(0)
D
2

The image title attribute should describe the image.

The link title attribute should describe the target of the link.

<a title="view larger version" href="#">
  <img title="image description" alt="image description" src="image.jpg">
</a>
Data answered 3/11, 2013 at 17:48 Comment(2)
In practice it seems that the image title takes precedence when hovering with a mouse. I tested with Safari, Chrome, and Firefox on macOS. When the img title is removed the a link title is shown on hover.Badtempered
@Badtempered In that case, you can add pointer-events: none; on your image to prevent this behaviourPurchasable

© 2022 - 2024 — McMap. All rights reserved.