Try role="listitem"
or role="group"
and aria-labelledby="shopping cart items"
. See Example 1. The 2
is text content which should be read by screen reader already with the attribute read as context to the content. Refer to this section.
UPDATE 2
Add aria-readonly=true
role=textbox
if you use an input. If there are doubts whether to use aria-label
or aria-labelledby
, read this article. In the documentation for JAWS and testing it myself supports the fact that aria-label
is ignored. Furthermore, semantics are very important when accessibility is your concern. Using a div when you could use an input is not semantically sound and like I said before, JAWS would accept a form element more readily than a div. I assume that this "shopping cart" is a form or part of a form, and if you don't like it's borders, input {border: 0 none transparent}
or use <output>
* which would be A+ as far as semantics are concerned.
Sorry, @RadekPech reminded me; I forgot to add that using aria-labelledby
needs visible text and that the text needs an id which is also listed as the value(s) of aria-labelledby
. If you don't want text because of aesthetics, use color: transparent
, line-height: 0
, or color:<same as background>
. That should satisfy visibility as far as the DOM is concerned* and still be invisible to the naked eye. Keep in mind these measures are because JAWS ignores aria-label
.
*untested
EXAMPLE 3
<span id="shopping">Shopping</span>
<span id="cart">Cart</span>
<span id="items">Items</span>
<input id='cart' tabindex="0" aria-readonly=true readonly role="textbox" aria-labelledby="shopping cart items" value='2'>
UPDATE 1
For JAWS, you probably have to configure it a little:
- Click the Utilities menu item.
- Then Settings Center.
- Speech and Sounds Schemes
- Modiy Scheme...
- HTML Tab
In this particular dialog box, you can add specific attributes and what is said when an element is tabbed to. JAWS will respond to form elements easier because they can trigger the focus
event. You'll have an easier time doing Example 2 instead:
EXAMPLE 1
<div id=myCoolDiv tabindex="0" role="listitem" aria-labelledby="shopping cart items"> 2 <div>
EXAMPLE 2
<input id='semantic' tabindex="0" role="listitem" aria-labelledby="shopping cart items" value='2' readonly>
title
attribute is read by screen readers? The HTML5 spec explicitly discourages its use for accessibility. – rvighnetabindex
on anything that isn't a real control. – aardriansr-only
class for your purpose. – user2560539aria-label
, becauseDIV
have no default ARIArole
. You must setrole
to have thearia-*
attributes activates. – Radek Pech