This Wiki page is edited by participants of the WCAG Working Group. It does not necessarily represent consensus and it may have incorrect information or information that is not supported by other Working Group participants, WAI, or W3C. It may also have some very useful information.

Using aria-labelledby for link purpose

From WCAG WG
Revision as of 11:52, 4 September 2013 by Lguarino (Talk | contribs)

Jump to: navigation, search


Status

Applicability

WAI-ARIA, HTML5

This technique applies to:

User agent and assistive technology support notes [To be published separately]

Please see user agent ARIA support: [1]

Testing as of July 2012

Using VoiceOver 3 with Safari 5.1.3. On focus the link text 'Read more' was announced first with the referenced aria-labelledby content announced second.

Screen reader testing as of 22 October 2012

  • Not supported:
    • Win 7, IE 9, JAWS 13
    • Win 7, FF 13, NVDA 2012.2.1
    • Win XP, FF 15.0, NVDA 2011.3
    • Win XP, IE 8, SaToGo
  • Partial support (both link text and element referenced by aria-labeledby are read):
    • Win 7, IE9, NVDA 2012.2.1 (but Example 2 not supported)
    • Win XP, IE 8, NVDA 2011.3 (but Example 2 not supported)
  • Supported:
    • Win 7, FF 13, JAWS 13 (but Example 2 has only partial/buggy support: "Sales report 2012" is read twice)
    • Mac OS 10.5.8, VoiceOver

See full testing results for Example 1

See full testing results for Example 2

David tested on Aug 25, 2013... Example 2 and 3 are still not sufficiently supported.

    • Example 1 ok on JAWS, VoiceOver. NVDA ignores labelledby on an anchor
    • Example 2: JAWS 14 in FF, IE 10 read the entire paragraph for each link which is confusing and chatty. VoiceOver for Mountain Lion in Safari 6 same as JAWS. NVDA ignores labelledby on an anchor (unsuccessful implementation)
    • Example 3: JAWS 14 in FF, IE 10 read the entire paragraph for each link which is confusing and chatty, VoiceOver for Mountain Lion in Safari 6 OK. NVDA ignores labelledby on an anchor (unsuccessful implementation)

Description

With the aria-labelledby attribute, authors can use a visible text element on the page as a label for a focusable element (a form control or a link). For example, a "read more..." link could be associated with the text of the heading of the preceding section to make the purpose of the link unambiguous (see example 1).

When associating text to a focusable element with the help of aria-labelledby, the target text element is given an ID which is referenced in the value of the aria-labelledby attribute of the focusable element.

It is also possible to use several text elements on the page as a label for a focusable element. Each of the text elements used must be given a unique ID which is referenced as a string of IDs (IDREF) in the value of the aria-labelledby attribute. The label text should then be concatenated following the order of IDs in the value of the aria-labelledby attribute.

When applied on links, aria-labelledby can be used to identify the purpose of a link that may be readily apparent for sighted users, but less obvious for screen reader users.

The specified behavior of aria-labelledby is that the associated label text is announced instead of the link text (not in addition to the link text). When the link text itself should be included in the label text, the ID of the link should be referenced as well in the string of IDs forming the value of the aria-labelledby attribute.

Examples

Example 1

This example should replace the "read more" link text at the end of the teaser text with the content of the h2 heading referenced by aria-labelledby.

<h2 id="headline">Storms hit east coast</h2>

<p>Torrential rain and gale force winds have struck the east coast, causing flooding in many coastal towns.
   <a href="news.html" aria-labelledby="headline">Read more...</a></p>

Example 2

The following example concatenates a link name through aria-labelledby referencing both the report title, "2012 Sales Report", and the respective file type, (PDF, Word, or Powerpoint).

<p id="report-title">Download 2012 Sales Report:
<a aria-labelledby="report-title pdf" href="#" id="pdf">PDF</a> |
<a aria-labelledby="report-title doc" href="#" id="doc">Word</a> |
<a aria-labelledby="report-title ppt" href="#" id="ppt">Powerpoint</a></p>

Example 3

There may be cases where an author will placed a tag around a section of code that will be referenced.

Note: The use of tabindex="-1" on the span element is not meant to support focusing by scripts - here, it merely serves to ensure that some browsers (IE9, IE10) will include the span element in the accessibility tree, thus making it available for reference by aria-labelledby. For more details see Accessible HTML Elements

<p>Download <span id="report-title" tabindex="-1">2012 Sales Report</span>:
<a aria-labelledby="report-title pdf" href="#" id="pdf">PDF</a> |
<a aria-labelledby="report-title doc" href="#" id="doc">Word</a> |
<a aria-labelledby="report-title ppt" href="#" id="ppt">Powerpoint</a></p>

Tests

For each link that has an aria-labelledby attribute:

  1. Check that each ID in the value of the aria-labelledby attribute matches an ID of a text element used as part of the link purpose.

Expected results

Test #1 is true for the ID (or each of the IDs) referenced by aria-labelledby.