Use cases for title attribute on img element?

Events happening in the community are now at Drupal community events on www.drupal.org.
hughbris's picture

Hi

I'm pretty new at working with the Drupal API. Developing on D6, I've noticed that the core theme_image() function will output an empty title attribute value if none is supplied, e.g.

<img src="myimage.png" alt="my image description" title="" />
(In the case of @alt, blank is actually a good default BTW.)

I could see this being a problem if the image is hyperlinked, where the link itself uses a title attribute, e.g.

<!-- lines split for readability -->
<a href="myfunction.html" title="Do this thing">
  <img src="myimage.png" alt="my image description" title="" />
</a>

This actually happens when invoking the standard views_handler_field_contact_link->render() method from the core Contact module's views handlers when you choose to render a contact link as a mail icon:

<a href="/user/x/contact" title="Contact Hugh">
  <img src="/misc/forum-new.png" alt="" title="" width="16" height="16" />
</a>

Which title attribute does the browser render, the outer or the inner? I'm into standards more than user agent testing, but my Firefox 6 and Konqueror thankfully do what I want and render the outer @title as a tooltip. However, I don't like taking unnecessary risks with this kind of ambiguous markup. Who knows what some weird and wonderful devices and user agents might make of this? A semantically-augmented accessibility red light goes on.

It leads me to ask why a @title would be needed on an image. I know it's totally valid (doctype-wise) and distinct from @alt, but what's a use case for img/@title outside of when it's hyperlinked?

I notice the 7 & 8 APIs will not output an attribute if not supplied as an argument. That's good, but the APIs still kind of elevate @title to a first class attribute on <img/>, by virtue of including it as an enumerated key in $variables. That is, it's treated like @src, @alt, @width, and @height. I can imagine this leading developers to thinking they should include this attribute when they invoke theme_image().

If we can't find a good use case for img/@title, should we take 'title' out of the enumerated keys in $variables in D8?

Further, would it be a good idea to somehow fail or warn when @alt is not supplied? It is a required attribute according to the doctype. As D7 & D8 have it, the attribute is not present when not supplied. I don't know what the Drupalest way to handle this is, just throwing it out there as something we might catch in some way. Drupal's philosophy on handling/preventing such errors is unknown to me.

Cheers

Comments

rights statements!

hughbris's picture

Just thought of a use case. I have seen img/@title used on some media sites in unlinked photos to say something like "© The Photographer, 2007". Arguably, this would be better expressed as RDFa metadata, but it's a use case.

If we call it an edge case, you can still populate a title attribute using the "miscellaneous attributes" parameters in all versions of the theme_image() function anyway.

Accessibility

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: