2

Does every single div, section, main, and article need to have the role attribute for accessibility? Only asking because a colleague mentioned that, and now I feel like I have to redo a lot of markup. For instance, what if you're using a div for styling purposes?

Let's say I have HTML that looks like:

<div role="Heading" aria-labelledby="website-heading">
    <h1>This is a heading</h1>
    <hr>
</div>

Is role="Heading" necessary in this instance?

landofall
  • 41
  • 5
  • 1
    I would say: No. – Mischa Jul 14 '17 at 21:33
  • question has already been answered: https://stackoverflow.com/questions/10403138/what-is-the-purpose-of-the-role-attribute-in-html – DCR Jul 14 '17 at 21:35
  • @DCR Good find. In the future, you can just click the flag link below the question, select should be closed, duplicate of, then paste that link right in there. Thanks! – Heretic Monkey Jul 14 '17 at 21:37

2 Answers2

1
<div role="Heading" aria-labelledby="website-heading">
    <h1>This is a heading</h1>
    <hr>
</div>

The heading role is not only non-necessary but uncorrect.

This would mean that the inner <h1> has a parent heading with a aria-level which can't exist as h1 is the first existing level within headings.

Adam
  • 17,838
  • 32
  • 54
-1

No its not compulsory or a good practice to add role attribute to every div or section you have in a page. If you want to remember the roles of your different sections or div's then you can always use html comments