Don’t Wrap Figure in a Link

In my post Brief Note on Figure and Figcaption Support I demonstrate how, when encountering a figure with a screen reader, you won’t hear everything announced at once:

No screen reader combo treats the caption as the accessible name nor accessible description, not even for an image that lacks one.

All Is Well

This is a good thing. Users don’t want to hear the media alternative (alt text) and then the caption all as a flat, uninterrupted string. Then hear it a second time as they navigate into the figure.

This is because the <figure> element (or, rather, its implicit role) does not allow name from content. It’s just a container.

But Then You Wrap It in a Link

This becomes a problem when you wrap the entire figure in a link. Something like this:

<a href="i-am-not-your-dad-final-v2-FINAL.html">
  <figure>
    <img src="figure-example_image.jpg"
       alt="A black t-shirt with bold pink all-caps text that reads ‘PUNCH NAZIS’.">
    <figcaption>The ‘PUNCH NAZIS’ tee we all need.</figcaption>
  </figure>
</a>

Now the link is wrapping a container that does not have an accessible name — remember it doesn’t get its name from its contents. It’s a not a text node.

Take a moment to guess how that might be announced.

Sometimes a browser and screen reader follow the rules, sometimes they decide meh, rules are worse for users.

That seems inconsistent at best and problematic for most. Imagine being a voice control user and trying to figure out what to speak. You’re better off throwing a numbered grid onto the screen.

And Then You Give the Link a title!?

But then this:

<a href="i-am-not-your-dad-final-v2-FINAL.html"
   title="Appropriate for casual Friday.">
  <figure>
    <img src="figure-example_image.jpg"
       alt="A black t-shirt with bold pink all-caps text that reads ‘PUNCH NAZIS’.">
    <figcaption>The ‘PUNCH NAZIS’ tee we all need.</figcaption>
  </figure>
</a>

The title attribute provides only the accessible description for a link. Unless the link has no accessible name, such as from contents. Step E, Host Language Label in the Accessible Name Computation specification says, for this scenario, the title becomes the accessible name.

Scroll back up and take a moment to guess how that might be announced.

In short, adding title hides the contents of the figure from the majority of screen reader users. That’s bad.

What to Do?

Don’t wrap <figure> in a link.

If you do it anyway, don’t make it worse by adding a title (or other accessible name technique) to that link.

If you have a boss / client insisting the entire figure must be clickble / tappable, then consider a block link. It’s not ideal, but it is less overtly user hostile.

For a fun party game, guess how all other roles / HTML elements that do not get name from content would behave in the same scenario. Write it down. Then test it similarly to my example. Keep score. Don’t do it as a drinking game.

Don’t Believe Me?

Fine. Test it yourself. Or use the embed below.

No comments? Be the first!

Leave a Comment or Response

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>