14

Are there any benefits of using the following code?

<ul role="list">
    <li role="listitem"></li>
    <li role="listitem"></li>
    <li role="listitem"></li>
</ul>

Does the following code have the same meaning to assistive technologies?

<ul>
    <li></li>
    <li></li>
    <li></li>
</ul>
James Skemp
  • 8,018
  • 9
  • 64
  • 107
Ian Y.
  • 2,293
  • 6
  • 39
  • 55

2 Answers2

26

The answer is yes, assistive technologies work well when correct semantic markup is used for structuring the document. If it is a simple static list then there is no need to mark them with the roles.

For example: Consider the role="listitem" whose baseConcept is defined as HTML li. And the baseConcept HTML li is almost identical to the role="listitem" definition except for the fact that it does not inherit any properties. More info

Thus, consider the following example:

<h3 id="header">Vegetables</h3>
   <ul role="list" aria-labelledby="header" aria-owns="external_listitem">
     <li role="listitem" aria-level="3">Carrot</li>
     <li role="listitem" aria-level="3">Tomato</li>
     <li role="listitem" aria-level="3">Lettuce</li>
   </ul>
…
<div role="listitem" id="external_listitem">Asparagus</div>

Here the page author wants to use aria-level property for the li. Even though aria-labelledby and aria-owns can be applied to all elements of base markup, aria-level property requires that the element have some role. Since ARIA spec uses Web Ontology Language (OWL) to represent the roles in a class hierarchy. OWL describes these roles as classes along with their states and properties. So inorder to use a aria-level the element has to be defined some role as plain HTML li will not inherit any properties or limitations. Once you mark the role as listitem it requires that listitem be owned by an element with role="list". So you end up using both the roles.

On the other hand roles are also useful if semantic markup is also not used. For example:

<div role="list">
  <div role="listitem">dog</div>
  <div role="listitem">cat</div>
  <div role="listitem">sparrow</div>
  <div role="listitem">wolf!</div>
</div>

Here the screen reader software will indicate the ARIA list (made up of divs) as any other normal HTML list.

Ravi Kadaboina
  • 8,494
  • 3
  • 30
  • 42
  • Thanks @Ravi for the info. So when semantic markup is used, there is no need to mark a simple static list with roles. – Ian Y. Jun 21 '12 at 05:02
  • 1
    Yes, almost all the time but it is again dependent on Accessibility Software used along with the browser version. So if you find that a particular markup is not being read by screen reader it supposed to be then use a combination of these roles to make it work until the software is fixed with that defect. So nothing is definite just do thorough testing. – Ravi Kadaboina Jun 21 '12 at 05:07
  • 3
    Why does this answer say "The answer is yes", and then go on to explain in laborious detail that the answer is no? It's clearly no. The answer is no, there is no benefit to putting these roles on `
      ` and `
    • ` elements, which is definitely, unambiguously what the question asked.
    – callum Jun 30 '22 at 08:20
10

You question is a bit ambiguous, but if you are asking whether there's a benefit to adding role="listitem" to li items, which already have that as their default role, then the answer to that specific question is 'No.'

(Yes, the use of a li is preferred instead of a div. And role="listitem" is needed if you were using a div. But I don't think that's quite what you are asking.)

Check out Using ARIA by Steve Faulkner; he's put together a draft best-practices document on when and where to use the various ARIA roles in HTML5.

Generally speaking, you don't need to (and shouldn't) specify a role for elements if that role is the same as the element's default role. So since li elements have a default role of listitem, there's no reason to restate that.

There are some exceptions to this rule, and they're mostly concerned with new HTML5 elements that browsers have not yet correctly implemented default roles for. So, for example, since HTML5's article element isn't yet exposed by all browsers as having a role of article, then <article role='article'> is actually recommended in that and similar cases.

James Skemp
  • 8,018
  • 9
  • 64
  • 107
BrendanMcK
  • 14,252
  • 45
  • 54
  • 2
    hi Brendan, the current URL for Using ARIA in HTML- http://dvcs.w3.org/hg/aria-unofficial/raw-file/tip/index.html will always point to the editors draft of the document. – Steve Faulkner Jul 23 '12 at 18:13
  • 3
    It looks like Steve's "Notes on Using ARIA in HTML" lives here now: https://www.w3.org/TR/aria-in-html/ – Ryan Grove Apr 14 '17 at 17:34