• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<div id="pageData-name" class="pageData">Accessibility (a11y)</div>
2<div id="pageData-showTOC" class="pageData">true</div>
3
4<p>
5When you design an extension,
6try to make it as accessible as possible
7to people with disabilities such as
8visual impairment, hearing loss, and limited dexterity.
9</p>
10
11<p>
12Everyone &mdash; not just people with special needs &mdash;
13can benefit from the alternative access modes
14that accessible extensions provide.
15For example, keyboard shortcuts are important
16for blind people and people with limited dexterity,
17but they also help power users get things done
18more quickly without using a mouse.
19Captions and transcripts give deaf people access to audio content,
20but they are also useful to language learners.
21</p>
22
23<p>
24People can interact with your extension in a variety of ways.
25They might use a standard monitor, keyboard, and mouse,
26or they might use a screen magnifier and just a keyboard.
27Another possibility is a <em>screen reader</em>,
28an assistive application tool that interprets
29what's displayed onscreen
30for a blind or visually impaired user.
31A screen reader might speak out loud or produce Braille output.
32</p>
33
34<p>
35Although you can't predict what tools people will use,
36by following a few simple guidelines
37you can write an extension that is
38more likely to be accessible to more people.
39The guidelines on this page aren't going to
40make your extension accessible for absolutely everyone,
41but they're a good starting point.
42</p>
43
44
45<h2 id="controls">Use accessible UI controls</h2>
46
47<p>
48First, use UI controls that support accessibility.
49The easiest way to get an accessible control is to use a
50standard HTML control.
51If you need to build a custom control,
52keep in mind that it's much easier
53to make the control accessible from the beginning
54than to go back and add accessibility support later.
55</p>
56
57<h3 id="htmlcontrols">Standard controls</h3>
58
59<p>
60Try to use standard HTML UI controls whenever possible.
61Standard HTML controls (shown in the following figure)
62are keyboard accessible, scale easily,
63and are generally understood by screen readers.
64</p>
65
66<img src="images/a11y/standard-html-controls.png"
67 width="550" height="350"
68 alt="Screenshots and code for button, checkbox, radio, text, select/option, and link">
69
70
71<h3 id="aria">ARIA in custom controls</h3>
72
73<p>
74ARIA is a specification for making UI controls accessible to screen readers
75by means of a standard set of DOM attributes.
76These attributes provide clues to the screen reader
77about the function and current state of controls on a web page.
78ARIA is a
79<a href=" http://www.w3.org/WAI/intro/aria">work in progress at the W3C</a>.
80</p>
81
82<p>
83Adding ARIA support to custom controls in your extension
84involves modifying DOM elements to add attributes
85Google Chrome uses
86to raise events during user interaction.
87Screen readers respond to these events
88and describe the function of the control.
89The DOM attributes specified by ARIA are classified into
90<em>roles</em>, <em>states</em>, and <em>properties</em>.
91</p>
92
93<p>
94The ARIA attribute <em>role</em>
95is an indication of the control type
96and describes the way the control should behave.
97It is expressed with the DOM attribute <code>role</code>,
98with a value set to one of the pre-defined ARIA role strings.
99Because ARIA roles are static,
100the role attribute should not change its value.
101</p>
102
103<p>
104The <a href="http://www.w3.org/WAI/PF/aria/roles">ARIA Role Specification</a>
105holds detailed information on how to pick the correct role.
106For example, if your extension includes a toolbar,
107set the <code>role</code> attribute of the toolbar's DOM element as follows:
108</p>
109
110<pre>
111&lt;div role="toolbar"&gt;
112</pre>
113
114<p>
115ARIA attributes are also used to describe
116the current state and properties of controls of a particular role.
117A <em>state</em> is dynamic and should be updated during user interaction.
118For example, a control with the role "checkbox"
119could be in the states "checked" or "unchecked".
120A <em>property</em> is not generally dynamic,
121but is similar to a state
122in that it expresses specific information about a control.
123For more information on ARIA states and properties,
124refer to the
125<a href="http://www.w3.org/TR/wai-aria/states_and_properties">W3C States and Properties specification</a>.
126</p>
127
128
129<p class="note">
130<b>Note:</b>
131You don't have to use
132all of the states and properties available for a particular role.
133</p>
134
135<p>
136Here's an example of adding
137the ARIA property <code>aria-activedescendant</code>
138to the example toolbar control:
139</p>
140
141<pre>
142&lt;div role="toolbar" tabindex="0" aria-activedescendant="button1"&gt;
143</pre>
144
145<p>
146The
147<a href="http://www.w3.org/WAI/PF/aria/states_and_properties#aria-activedescendant"><code>aria-activedescendant</code></a>
148property specifies which child of the toolbar receives focus
149when the toolbar receives focus.
150In this example, the toolbar's first button
151(which has the <code>id</code> "button1")
152is the child that gets focus.
153The code <code>tabindex="0"</code>
154specifies that the toolbar
155receives focus in document order.
156</p>
157
158<p>
159Here's the complete specification for the example toolbar:
160</p>
161
162<pre>
163&lt;div role="toolbar" tabindex="0" aria-activedescendant="button1"&gt;
164  &lt;img src="buttoncut.png" role="button" alt="cut" id="button1"&gt;
165  &lt;img src="buttoncopy.png" role="button" alt="copy" id="button2"&gt;
166  &lt;img src="buttonpaste.png" role="button" alt="paste" id="button3"&gt;
167&lt;/div&gt;
168</pre>
169
170<p>
171Once ARIA roles, states, and properties are added to the DOM of a control,
172Google Chrome raises the appropriate events to the screen reader.
173Because ARIA support is still a work in progress,
174Google Chrome might not raise an event for every ARIA property,
175and screen readers might not recognize all of the events being raised.
176You can find more information on ARIA support in Google Chrome in the
177<a href="http://www.chromium.org/developers/design-documents/accessibility#TOC-WAI-ARIA-Support">Chromium Accessibility Design Document</a>.
178</p>
179
180<p>
181For a quick tutorial on adding ARIA controls to custom controls, see
182<a href="http://www.w3.org/2010/Talks/www2010-dsr-diy-aria/">Dave Raggett's presentation from WWW2010</a>.
183
184<h3 id="focus">Focus in custom controls</h3>
185
186<p>
187Make sure that operation and navigation controls of your extension
188can receive keyboard focus.
189Operation controls might include
190buttons, trees, and list boxes.
191Navigation controls might include tabs and menu bars.
192</p>
193
194<p>
195By default, the only elements in the HTML DOM
196that can receive keyboard focus
197are anchors, buttons, and form controls.
198However, setting the HTML attribute <code>tabIndex</code> to <code>0</code>
199places DOM elements in the default tab sequence,
200enabling them to receive keyboard focus.
201For example:
202</p>
203
204<pre>
205<em>element</em>.tabIndex = 0
206</pre>
207
208<p>
209Setting <code>tabIndex = -1</code> removes the element from the tab sequence
210but still allows the element to receive keyboard focus programmatically.
211Here's an example of setting keyboard focus:
212</p>
213
214<pre>
215<em>element</em>.focus();
216</pre>
217
218<p>
219Ensuring that your custom UI controls include keyboard support
220is important not only for users who don't use the mouse
221but also because screen readers use keyboard focus
222to determine which control to describe.
223</p>
224
225<h2 id="keyboard"> Support keyboard access </h2>
226
227<p>
228People should be able to use your extension
229even if they can't or don't want to use a mouse.
230</p>
231
232<h3 id="navigation"> Navigation </h3>
233
234<p>
235Check that the user can navigate between
236the different parts of your extension
237without using the mouse.
238Also check that any popups on page actions or browser actions
239are keyboard navigable.
240</p>
241
242<p id="builtin">
243On Windows, you can use <b>Shift+Alt+T</b>
244to switch the keyboard focus to the toolbar,
245which lets you navigate to the icons of page actions and browser actions.
246The help topic
247<a href="http://www.google.com/support/chrome/bin/static.py?hl=en&page=guide.cs&guide=25799&from=25799&rd=1">Keyboard and mouse shortcuts</a>
248lists all of Google Chrome's keyboard shortcuts;
249details about toolbar navigation
250are in the section <b>Google Chrome feature shortcuts</b>.
251</p>
252
253<p class="note">
254<b>Note:</b>
255The Windows version of Google Chrome 6 was the first
256to support keyboard navigation to the toolbar.
257Support is also planned for Linux.
258On Mac OS X,
259access to the toolbar is provided through VoiceOver,
260Apple's screenreader.
261</p>
262
263<p>
264Make sure that it's easy to see
265which part of the interface has keyboard focus.
266Usually a focus outline moves around the interface,
267but if you’re using CSS heavily this outline might be suppressed
268or the contrast might be reduced.
269Two examples of focus outline follow.
270</p>
271
272<img src="images/a11y/focus-outline-2.png"
273  width="200" height="75"
274  alt="A focus outline on a Search button">
275<br />
276<img src="images/a11y/focus-outline.png"
277  width="400" height="40"
278  alt="A focus outline on one of a series of links">
279
280
281<h3 id="shortcuts"> Shortcuts </h3>
282
283<p>
284Although the most common keyboard navigation strategy involves
285using the Tab key to move focus through the extension interface,
286that's not always the easiest or most efficient way
287to use the interface.
288You can make keyboard navigation easier
289by providing explicit keyboard shortcuts.
290</p>
291
292<p>
293To implement shortcuts,
294connect keyboard event listeners to your controls.
295A good reference is the DHTML Style Guide Working Group’s
296<a href="http://dev.aol.com/dhtml_style_guide">guidelines for keyboard shortcuts</a>.
297</p>
298
299<p>
300A good way to ensure discoverability of keyboard shortcuts
301is to list them somewhere.
302Your extension’s
303<a href="options.html">Options page</a>
304might be a good place to do this.
305</p>
306
307<p>
308For the example toolbar,
309a simple JavaScript keyboard handler could look like the following.
310Note how the ARIA property <code>aria-activedescendant</code>
311is updated in response to user input
312to reflect the current active toolbar button.
313</p>
314
315<pre>
316&lt;head&gt;
317&lt;script&gt;
318 function optionKeyEvent(event) {
319  var tb = event.target;
320  var buttonid;
321
322  ENTER_KEYCODE = 13;
323  RIGHT_KEYCODE = 39;
324  LEFT_KEYCODE = 37;
325  // Partial sample code for processing arrow keys.
326  if (event.type == "keydown") {
327    // Implement circular keyboard navigation within the toolbar buttons
328    if (event.keyCode == ENTER_KEYCODE) {
329      ExecuteButtonAction(getCurrentButtonID());
330      <em>// getCurrentButtonID defined elsewhere </em>
331    } else if (event.keyCode == event.RIGHT_KEYCODE) {
332      // Change the active toolbar button to the one to the right (circular).
333      var buttonid = getNextButtonID();
334      <em>// getNextButtonID defined elsewhere </em>
335      tb.setAttribute("aria-activedescendant", buttonid);
336    } else if (event.keyCode == event.LEFT_KEYCODE) {
337      // Change the active toolbar button to the one to the left (circular).
338      var buttonid = getPrevButtonID();
339      <em>// getPrevButtonID defined elsewhere </em>
340      tb.setAttribute("aria-activedescendant", buttonid);
341    } else {
342      return true;
343    }
344    return false;
345  }
346}
347&lt;/script&gt;
348
349&lt;div role="toolbar" tabindex="0" aria-activedescendant="button1" id="tb1"
350     onkeydown="return optionKeyEvent(event);"
351     onkeypress="return optionKeyEvent(event);"&gt;
352  &lt;img src="buttoncut" role="button" alt="cut" id="button1"&gt;
353  &lt;img src="buttoncopy" role="button" alt="copy" id="button1"&gt;
354  &lt;img src="buttonpaste" role="button" alt="paste" id="button1"&gt;
355&lt;/div&gt;
356</pre>
357
358
359<h2 id="more"> Provide accessible content </h2>
360
361
362<p>
363The remaining guidelines might be familiar
364because they reflect good practices for all web content,
365not just extensions.
366</p>
367
368<h3 id="text">Text</h3>
369
370<p>
371Evaluate your use of text in your extension.
372Many people might find it helpful
373if you provide a way to increase the text size within your extension.
374If you are using keyboard shortcuts,
375make sure that they don't interfere with
376the zoom shortcuts built into Google Chrome.
377</p>
378
379<p>
380As an indicator of the flexibility of your UI,
381apply the <a href="http://www.w3.org/TR/2008/REC-WCAG20-20081211/#visual-audio-contrast-scale">200% test</a>.
382If you increase the text size or page zoom 200%,
383is your extension still usable?
384</p>
385
386<p>
387Also, avoid baking text into images:
388users cannot modify the size of text displayed as an image,
389and screenreaders cannot interpret images.
390Consider using a web font instead,
391such as one of the fonts collected in the
392<a href="http://code.google.com/apis/webfonts/">Google Font API</a>.
393Text styled in a web font is searchable,
394scales to different sizes,
395and is accessible to people using screen readers.
396</p>
397
398<h3 id="colors">Colors</h3>
399
400<p>
401Check that there is sufficient contrast between
402background color and foreground/text color in your extension.
403<a href="http://snook.ca/technical/colour_contrast/colour.html">This contrast checking tool</a>
404checks whether your background and foreground colors
405provide appropriate contrast.
406If you’re developing in a Windows environment,
407you can also enable High Contrast Mode
408to check the contrast of your extension.
409When evaluating contrast,
410verify that every part of your extension that relies on
411color or graphics to convey information is clearly visible.
412For specific images, you can use a tool such as the
413<a href="http://www.vischeck.com/vischeck/">Vischeck simulation tool</a>
414to see what an image looks like in various forms of color deficiency.
415</p>
416
417<p>
418You might consider offering different color themes,
419or giving the user the ability to customize the color scheme
420for better contrast.
421</p>
422
423<h3 id="sound">Sound</h3>
424
425<p>
426If your extension relies upon sound or video to convey information,
427ensure that captions or a transcript are available.
428See the
429<a href="http://www.dcmp.org/ciy/">Described and Captioned Media Program guidelines</a>
430for more information on captions.
431</p>
432
433<h3 id="images">Images</h3>
434
435<p>
436Provide informative alt text for your images.
437For example:
438</p>
439
440<pre>
441&lt;img src="img.jpg" alt="The logo for the extension"&gt;
442</pre>
443
444<p>
445Use the alt text to state the purpose of the image
446rather than as a literal description of the contents of an image.
447Spacer images or purely decorative images
448should have blank ("") alt text
449or be removed from the HTML entirely and placed in the CSS.
450</p>
451
452<p>
453If you must use text in an image,
454include the image text in the alt text.
455A good resource to refer to is the
456<a href="http://www.webaim.org/techniques/alttext/">WebAIM article on appropriate alt text</a>.
457
458<h2 id="examples">Examples</h2>
459
460<p>
461For an example that implements keyboard navigation and ARIA properties, see
462<a href="http://src.chromium.org/viewvc/chrome/trunk/src/chrome/common/extensions/docs/examples/extensions/news_a11y/">examples/extensions/news_a11y</a>
463(compare it to
464<a href="http://src.chromium.org/viewvc/chrome/trunk/src/chrome/common/extensions/docs/examples/extensions/news/">examples/extensions/news</a>).
465For more examples and for help in viewing the source code,
466see <a href="samples.html">Samples</a>.
467
468