WAI-ARIA, the Accessible Rich Internet Applications Suite, defines a way to make Web content and Web applications more accessible to people with disabilities. It especially helps with dynamic content and advanced user interface controls developed with AJAX, HTML, JavaScript, and related technologies. Currently certain functionality used in Web sites is not available to some users with disabilities, especially people who rely on screen readers and people who cannot use a mouse (e.g mobile devices users). WAI-ARIA addresses these accessibility challenges, for example, by defining new ways for functionality to be provided to assistive technology. (http://www.w3.org/WAI/intro/aria)
So, trying to make our content more accessible is a pretty important step in web development. By including roles, states and properties, ARIA helps us make our code semantically richer for the assistive technology user. ARIA enables semantic description of an element or widget behavior and enables information about groups and the elements within them. ARIA states and properties are accessible via the DOM.
A common use case is a navigation menu. Almost every site/blog out there has a tabbed navigation menu. How could we make these menus more accessible..? It just takes few attributes in our dom elements, such as "role".
The ARIA "role" attribute
Therole
attribute enables us to create semantic structure on elements. Two notes about roles:
- once set, a role should not be dynamically changed, since this will confuse the assistive technology
- roles take precendence over element default semantic meaning
Menu Example
Here is a simple menu we see in many sites:<div class="topMenuWrapper"> <div class="topMenuWrapperInner"> <ul class="topMenuList"> <li class="topMenuListItem"> <a href="#"><span class="menuItemContent">Menu item 1</span></a> </li> <li class="topMenuListItem"> <a href="#"><span class="menuItemContent">Menu item 2</span></a> </li> <li class="topMenuListItem"> <a href="#"><span class="menuItemContent">Menu item 3</span></a> </li> <li class="topMenuListItem"> <a href="#"><span class="menuItemContent">Menu item 4</span></a> </li> </ul> </div> </div>By the way, here is the CSS to make a working example, with horizontal tabs:
body { background-color: #F8F8F8; } .topMenuWrapperInner { margin: 5em; float: right; } .topMenuList { margin: 0px; } .topMenuListItem { margin-right: 10px; padding: 6px; display:inline; background-color: #ddd; border: 1px solid #ddd; /* lets add rounded corners for real browsers :P */ -webkit-border-top-left-radius:5px; -webkit-border-top-right-radius:5px; -moz-border-radius-topleft:5px; -moz-border-radius-topright:5px; } .topMenuListItem a { color: #fff; text-decoration: none; font-weight: bold; } .topMenuListItem:hover { background-color: #fff; border: 1px solid #ddd; } .topMenuListItem:hover a { color: #B0B0B0; } .menuItemContent { padding:10px; }Now let's make our top menu accessible:
<div class="topMenuWrapper"> <div role="menu" class="topMenuWrapperInner"> <ul role="presentation" class="topMenuList"> <li role="presentation" class="topMenuListItem"> <a href="#" role="menuitem"> <span class="menuItemContent">Menu item 1</span> </a> </li> <li role="presentation" class="topMenuListItem"> <a href="#" role="menuitem"> <span class="menuItemContent">Menu item 2</span> </a> </li> <li role="presentation" class="topMenuListItem"> <a href="#" role="menuitem"> <span class="menuItemContent">Menu item 3</span> </a> </li> <li role="presentation" class="topMenuListItem"> <a href="#" role="menuitem"> <span class="menuItemContent">Menu item 4</span> </a> </li> </ul> </div> </div>Now let's see what each attribute means:
- role = menu: Offers a list of choices to the user.
- role = presentation: An element whose role is presentational does not need to be mapped to the accessibility API.
- role = menuitem: A link in a menu. This is an option in a group of choices contained in a menu.
- WAI-ARIA Best Practices, http://www.w3.org/TR/2008/WD-wai-aria-practices-20080204/
- WAI-ARIA Roles, http://www.w3.org/TR/wai-aria/usage#usage_intro