The Role Attribute

I have been researching the correct way to implement the role attribute and have come across some questions. The w3c spec contains this excerpt:

from http://dev.w3.org/html5/spec/content-models.html#annotations-for-assistive-technology-products-aria

“Authors may use the ARIA role and aria-* attributes on HTML elements, in accordance with the requirements described in the ARIA specifications, except where these conflict with the strong native semantics described below.”

And of course a table containing html elements and their native roles follows. So here are my questions, the first in reference to the above information.

  1. The term “conflict” brought about a bit of confusion. Do they mean that no other role should be applied other than the one(s) listed? That doesn’t sound right. If not, what constitutes a conflict being that multiple roles can be assigned? Only roles that directly conflict such as putting a “document” role on an li element?
  2. Should I steer clear of using attribute selectors in my CSS based on roles? I vaguely recall some versions of IE not supporting unrecognized attributes so my concern would be an older version of IE ignoring some of my css rules.
  3. I have seen multiple ways to create a navigation menu. What I’ve been doing is creating a ul with li’s that contain a elements and then applying styles to them. However I recently saw an example where the li elements themselves had an href attribute eliminating the need for the anchor element. With HTML 5 and it’s focus on semantics, I’d like to use a nav element and just anchor elements with the menuitem role applied. What are your thoughts?

I’ll give this one a try. I’ve been using some basic landmark roles in my pages, and a few ARIA attributes in forms… further nothing more.

The term “conflict” brought about a bit of confusion. Do they mean that no other role should be applied other than the one(s) listed? That doesn’t sound right. If not, what constitutes a conflict being that multiple roles can be assigned? Only roles that directly conflict such as putting a “document” role on an li element?

I believe they are saying if you have an element with a default semantic role (example, the <button> element having a “button” role) and then, I dunno, manually giving it a “presentation” role, the UA may choose to honour just one if the two are really incompatible.

You can have multiple roles, and multiple attributes, but I believe the document you linked to says IF there is a conflict, then you need to fix it (remove the conflict).

Should I steer clear of using attribute selectors in my CSS based on roles? I vaguely recall some versions of IE not supporting unrecognized attributes so my concern would be an older version of IE ignoring some of my css rules.

IE6 does not understand ANY attribute selectors.

IE7 understands attribute selectors. Also remember IE has special names for a label’s for (htmlFor) attribute and elements’ class (either class or className) attributes. It has small bugs like foo[bar]+somechild breaking.

IE8 still goofs a bit in tables but mostly supports attributes.

http://www.quirksmode.org/css/contents.html

I have seen multiple ways to create a navigation menu. What I’ve been doing is creating a ul with li’s that contain a elements and then applying styles to them. However I recently saw an example where the li elements themselves had an href attribute eliminating the need for the anchor element. With HTML 5 and it’s focus on semantics, I’d like to use a nav element and just anchor elements with the menuitem role applied. What are your thoughts?

So far as I remember, the “href on non-anchors” thing was an idea from XHTML2, which was scrapped because existing browsers wouldn’t understand/correctly use it, and HTML5 is all about backwards compatibility. Instead, HTML5 has decided to let authors wrap the normally-inline anchors around block elements, which gets around one of the reasons people wanted href attributes on non-links. I dunno if you can wrap an anchor around a table’s trs, but you can wrap it around a header or a div.

The true intended/planned semantics of HTML5 have not reached any actual browsers yet (it is in many betas such as FF4b and possibly the new Opera 11 has some). Who benefits the most directly from semantics? Other computer programs and users of accessibility technology. Currently I dunno which-all screen readers knows what a <nav> is and the ones who don’t recognise it are just seeing the <ul> tags inside. My understanding of <nav> tags is to wrap those <ul>s who are not just lists, but specifically (primary) navigation lists. A user hitting “l” key for all lists on the page is getting all lists… a user whose reader first reads out landmarks can choose to go specifically to the navigation landmark, regardless of whether that landmark was set on an actual ul or on a div containing many primary navigation uls.

As a note, the idea is that the role of “navigation” will be added as a default semantic role of the <nav> element. Currently this causes NVDA to think there are two navigation lists if you also manually add the “navigation” role to a ul already wrapped in a <nav> tag. The only browser I know of who will have these default roles for some HTML5 elements is the upcoming FF4 stable release.

Since I do not write HTML5 (for many reasons, here is one of them which will interest you) I use a regular ul like HTML4 and if I want to add a landmark navigation role to it, I do so. I do not go further with adding roles to the links (menuitem). To me that seems overkill. It’s probably more useful when you have a menu in a widget (where the elements you use don’t necessarily lend to the idea of menu items, but you are using them as such in conjunction with Javascript or something).

If you are writing HTML5 and using ARIA, you may be building a site for the future. It will not work nicely today with current browsers and screen readers. This is why I haven’t used anything of HTML5 beyond the nice doctype on any production pages. Another thing to remember is while AT is slowly getting a hang of both ARIA and HTML5, they are reliant on the accessibility layer of the browsers (some like Chrome haven’t had any at all, unless the latest latest release changed this) and then of course users have to update their readers. Some readers cost a lot, or were received from a school or government program and won’t be updated. So when JAWS doesn’t see <header> tags and their contents in Firefox at all, it’s a problem even though JAWS12 (the latest release) fixed that. Lots of users may still be using JAWS 9 or 10 (and some may be stuck on version 6 or 7 and therefore are stuck with IE6 for the most part… another reason to maybe consider supporting IE6).

Another issue to keep in mind with ARIA is that so far as I know, only screen readers are getting this useful information (mobiles are possibly going to be able to use these roles in the future though, and that sounds pretty cool). Sometimes I think I have a page with a bunch of lists and menus, and I want to point out the primary navigation with an actual header tag stating so.

Like when there are site menus and product menus, I’ll call them that.
<h2>Site menu</h2>
<ul>
blah blah
</ul>

<h2>Product menu</h2>
<ul>
blah blah
</ul>

This can let users of any type of linear browsing mode skip having to view the first few links to figure out what the menu’s about. If the page is really full/cluttered, it may even benefit sighted users with graphical browsers.

Hope this gives you some ideas. I don’t know what you’re building or who you are targeting it at, so my advice might be off-base for you. Also, a lot of it is my opinion and possibly some badly-outdated information.

Anyone working on HTML5 spec, ARIA spec, browser AT layers or AT software, would be highly appreciated if more better information could be added or corrected???

Wow thanks for the detailed response! The website in question is my company’s website and we do web design and development. We want to stay as cutting edge as possible so we have been considering the move to HTML5. I’ve read several threads that have convinced me the web might not be ready for the jump. I don’t want to have to worry about javascript workarounds for browsers that don’t support the new elements. I will, however, begin using the new doctype as I have determined it will not affect the user experience of those users with browsers that don’t support HTML5.

I guess my first two questions weren’t completely answered. I’m not sure anyone who is NOT working on the ARIA spec would be able to explicitly define what it means for two roles to be in “conflict.” Sure, there are some blatant conflicts like the one I mentioned above, but it becomes more vague for me when you want to apply the menuitem role to say, spans, li’s, buttons, etc. I might just have to wait until there is more information on the subject.

As for the attribute selectors, I may not have been clear enough as to what my worry was. I was aware which browsers do and do not support attribute selectors (though that site will be very useful for me in the future so thank you :p). My worry is what browsers support custom attributes. For instance, <div foo=“bar”>. If I create a style rule like [foo=“bar”] { color: red }, will this be read an interpreted by all major browsers? This ties into using role attributes because I could style certain elements by their roles, killing two birds with one stone, but if a browser doesn’t recognize the role attribute, it will toss that style, right?

As for IE6, I’m not really concerned with it anymore. Our target market is such that it is a non-issue. I was so happy when Google decided NOT to make Google Apps compatible with IE6. I think that people won’t change unless you force them to change. I’d like to see the movement on the design and development side thus forcing users to change if they want to experience their favorite pages. This is just a brief skimming of my opinion on this topic that we don’t really need to get into, but in terms of IE, I only need to support 7+.

Hi

“Authors must not set the ARIA role and aria-* attributes in a manner that conflicts with the semantics described in the following table” is because some HTML5 elements have implied ARIA roles.

For example, <nav> has a implied ARIA role of navigation. It does not make sense, for example, to say <nav role=main> because by definiton, navigation can’t be main content. The HTML5 validator knows this and will tell you that it’s invalid. Be careful, though: the rules are still in flux and as they’re not yet set the validator is using an earlier draft. You should follow @stevefaulkner on twitter to find out more.

Styling elements based on attribute selectors is a different question. ARIA roles and attributes are semantic - they have meaning. The fact that IE6 can’t style selectors like div[role=main] {color:green;} is a fault of IE6’s CSS engine and not ARIA.

Later versions of IE can style attribute selectors, if I recall correctly. I do not currently have an iron pentagram to hand and therefore cannot summon up IE7 to test that out.

(Added: oh, and Stomme poes is right: <li href=“”> is n XHTML2 construct which isn’t supported anywhere. Also note, some crufty screenreaders choke on HTML5 and ARIA being used together; see http://www.accessibleculture.org/blog/2010/11/html5-plus-aria-sanity-check/ for a full discussion)

I believe that FF and those guys would indeed style foo[bar], and that IE’s problems styling HTML5 elements is that indeed because it cannot style what it doesn’t recognise, IE needed Remy’s javascript crutch.

This should be easy enough to test, actually: Make a page with a valid element and a valid attribute, an invalid element with an invalid attribute (<foo bar=“baz”>), and a valid element with an ARIA role, and style all three. Check in the browsers you are planning to support. Check in mobiles while you’re at it.

I will, however, begin using the new doctype as I have determined it will not affect the user experience of those users with browsers that don’t support HTML5.
Correct, it’ll even work down to IE5! : )

Regarding Steve Falkner, he gave a talk with Han Hillen about issues with HTML5 (as it currently is, which is indeed still in development) at the Fronteers conference. http://fronteers.nl/congres/2010/sessions#html5-accessibility-is-it-ready-yet

I figured since you’re bothering with ARIA attributes anyways, that you are doing them for screen reader users principally. Since the site is commercial, that’s something you’ll have to reckon with.

Ah, a note:

an invalid element with an invalid attribute (<foo bar=“baz”>)

You’ll want to set this element to display: block as the very first thing if you want to see a style like a background colour. The browsers who will style custom/unknown elements will set them to display: inline by default, like they are doing with current HTML5 elements.

the rules for conforming use of ARIA in HTML5 are still being formulated, there are 2 currently competing sets of rules, neither are authoritative

the one in the spec:
http://dev.w3.org/html5/spec/content-models.html#annotations-for-assistive-technology-products-aria

and this one:
http://www.paciellogroup.com/blog/misc/HTML5/aria-html5-proposal.html

where the rules are in agreement you can be pretty sure that they will not change.

the table in http://www.paciellogroup.com/blog/misc/HTML5/aria-html5-proposal.html
lists all the html elements, the roles that can be used for each element are detailed in the 3rd column. Some have restrictions others do not. The restrictions are there to ensure that the use of ARIA semantics do not result in confusing information being exposed to assistive technology users.

The information in the second colum is mainly for implementors (browser vendors) telling them what ARIA roles correspond to what elements, so they can hook them up correctly to accessibility APIs.

so the short answer to your question
"Do they mean that no other role should be applied other than the one(s) listed? "
is yes, only use roles listed for elements listed. Note in the spec version of the rules many elements are not listed, if they are not listed they can have ANY role applied.

Alright great! Thanks for the info!

Which is why unless you are testing browser compatibility, testing out specifications and reporting bugs and making suggestions, you have no business using ANY of the parts of the HTML 5 specification in creating websites. ARIA Roles included.

After all, that’s why it’s called “DRAFT” and not “RECOMMENDATION”.

NOT that IMHO any of this HTML5 crap serves any legitimate purpose other than bloating out the markup, undoing the past decade worth of progress STRICT offered us, and placating the people who still sleaze out HTML 3.2 and slap a HTML 4 tranny doctype on it to call it “modern”.

BOTH of the proposed ARIA specs are nothing more than bloated garbage trying to do stuff that honestly, semantic markup and proper content order should be handling already. All you have to do is look at the retarded example on the page of ascii art in PRE tags to see just how silly/pointless it is.

<Scouse accent>Alright, alright, calm down, calm down! </Scouse accent>

Off Topic:

I believe you meant “For god sakes, John, Sit Down!”

Oh, good God! Consider yourself lucky that you have John Adams to abuse, for no sane man would tolerate it!

[ot]He was referring to the Scousers main catchphrase: http://en.wikipedia.org/wiki/The_Scousers

Though it was a pretty accurate statement by Jason regarding HTML5 undoing progress.[/ot]

Off Topic:

Which being a Yank I’ve never heard of… I don’t even know who Harry Enfield is.

Though I take it that’s the equivalent of “I’d buy that for a dollar” in the catch-phrase department?

Well, Smola, it seems Jeremy Keith was thinking something similar to you: use roles both as roles AND as styling hooks:

Again he doesn’t address IE, but again I am still thinking it’s IE who has trouble styling unknown tags. But I wonder if a greedier selector could work:
*[role=main] {
styles;
}

Yeah, resource hog and all, but for the landmark roles, you should only match a single element with that. Again, I dunno if IE would then see <section role=“main”> matches “*” and still puke though, without testing.

Dunno why I’m too lazy to do this, I’m somewhat interested. : )

I saw this article, but I don’t understand it. The attribute selector has been around for a long time. I’ve always thought it was good for people to start using semantic attributes to select elements rather than giving things meaningless IDs and classes, but what is advised in the article has been possible for a while.

It’s not that IE has trouble styling unknown elements, it’s that unknown elements aren’t created in the DOM properly when they’re parsed. It has no problem styling them as long as they end up in the DOM correctly by using the createElement workaround first.

No. You’re wrong in a number of ways. Recommendation status is a red herring when determining whether a spec is realistically usable. A call for implementations occurs once a draft reaches CR. It is absolutely fine to start using something once its beggining to be implemented. In many cases, specs are even implemented before the official call for implementations.

For example, look at CSS 2.1, it’s still a last call working draft (yes it was CR for a while, but even then it certainly wasn’t a recommendation), yet I don’t see you attacking the use of CSS 2.1.

According to the technical report process, a spec can’t even reach recommendation without first having successful implementations and usage.

As far as html5 in general goes…Strict DTDs? Do you know what you’re talking about? How can anyone still advocate the use of DTDs? They’re not useful and in reality they’ve almost never been useful for html.

Ah, this is what Remy’s shimmi-majiggy does? This makes sense, thanks. (I’ve never looked at his code, and maybe it’s obvious there; I will never build a page that current-use browsers can’t read the markup without scripting, except as a fun experiment for myself. Never for production pages).

It is absolutely fine to start using something once its beggining to be implemented. In many cases, specs are even implemented before the official call for implementations.

I think Crusty is sepcifically thinking back to when Microsoft went ahead with their IE browser using the box model that ended up not being the final box model. As an example.

But there being two specs for ARIA are indeed one reason I’m sticking to mostly just landmark roles for now. If they can’t agree on something and be clear on it, I cannot give that to a client, absolutely not.

How can anyone still advocate the use of DTDs? They’re not useful and in reality they’ve almost never been useful for html.

Since the promise of making our very own died with XHTML2, I thought DTDs were for the validators.

Of course we still need to include them in any non-HTML5 doctype or the browser assumes an incomplete doctype and quirks out on us. Beyond that, yes, we know browsers don’t actually look at the referrer url, or actually know the difference between Strict and Transitional. However many of us believe the ideas behind “Strict” are worthy and want to keep presentation out of markup as much as reasonably possible… which is easier when you have a validator shaking its finger at you.

According to the technical report process, a spec can’t even reach recommendation without first having successful implementations and usage.

Specifically, two minimum: two browsers/user agents on two OSes. This is what got ARIA going: Orca/Firefox on Linux and JAWS/IE on Windows.

That was microsoft’s failure.

Yes, this is kind of my point. DTDs aren’t parsed by browsers despite the fact that they technically should be if html implementations were true to SGML. Furthermore, Strict DTDs specifically, were never actually useful for anything but giving yourself a pat on the back when you saw the “This document was successfully validated…” message. HTML5 is a good spec, and it is much more realistic than separating HTML into different DTDs. I’m fairly certain the html4 strict DTD is used by many sites with invalid markup regardless of the content models/attributes/etc that it defines. It’s not like a strict DTD was preventing these things. The people who are going to use correct markup are going to use correct markup, and the people using bad markup are going to use bad markup - all of this is irrespective of any kind of DTDs out there.

Of course we still need to include them in any non-HTML5 doctype or the browser assumes and incomplete doctype and quirks out on us.

I’m arguing that we don’t need DTDs anymore, HTML5 has accomplished this by not having one at all. Yeah, unfortunately, documents still require a DOCTYPE declaration for historical reasons.

were never actually useful for anything but giving yourself a pat on the back when you saw the “This document was successfully validated…” message.

I wouldn’t underestimate this. How many newbies actually bother trying to fix their markup because they see red, when otherwise they wouldn’t have?

I’m fairly certain the html4 strict DTD is used by many sites with invalid markup regardless of the content models/attributes/etc that it defines. It’s not like a strict DTD was preventing these things.

It’s more the hippy-fundamentalist Berners-Lee-based ideal. Information should be free and available regardless of user agent; code should be semantic and simple. It’s just that the righteous and zealous are fewer in number than the nephews with copies of FrontPage. And all those in between.

Fair enough. However, I think a lot of aspects of the HTML4 strict DTD are impractical and unnecessary, specifically the content models.