1<h1>Accessibility (a11y)</h1> 2 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 — not just people with special needs — 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="{{static}}/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<div role="toolbar"> 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<div role="toolbar" tabindex="0" aria-activedescendant="button1"> 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<div role="toolbar" tabindex="0" aria-activedescendant="button1"> 164 <img src="buttoncut.png" role="button" alt="cut" id="button1"> 165 <img src="buttoncopy.png" role="button" alt="copy" id="button2"> 166 <img src="buttonpaste.png" role="button" alt="paste" id="button3"> 167</div> 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="{{static}}/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="{{static}}/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. 302{{?is_apps}} 303 Your application's options page 304{{:is_apps}} 305 Your extension's 306 <a href="options">Options page</a> 307{{/is_apps}} 308might be a good place to do this. 309</p> 310 311<p> 312For the example toolbar, 313a simple JavaScript keyboard handler could look like the following. 314Note how the ARIA property <code>aria-activedescendant</code> 315is updated in response to user input 316to reflect the current active toolbar button. 317</p> 318 319<pre> 320<head> 321<script> 322 function optionKeyEvent(event) { 323 var tb = event.target; 324 var buttonid; 325 326 ENTER_KEYCODE = 13; 327 RIGHT_KEYCODE = 39; 328 LEFT_KEYCODE = 37; 329 // Partial sample code for processing arrow keys. 330 if (event.type == "keydown") { 331 // Implement circular keyboard navigation within the toolbar buttons 332 if (event.keyCode == ENTER_KEYCODE) { 333 ExecuteButtonAction(getCurrentButtonID()); 334 <em>// getCurrentButtonID defined elsewhere </em> 335 } else if (event.keyCode == event.RIGHT_KEYCODE) { 336 // Change the active toolbar button to the one to the right (circular). 337 var buttonid = getNextButtonID(); 338 <em>// getNextButtonID defined elsewhere </em> 339 tb.setAttribute("aria-activedescendant", buttonid); 340 } else if (event.keyCode == event.LEFT_KEYCODE) { 341 // Change the active toolbar button to the one to the left (circular). 342 var buttonid = getPrevButtonID(); 343 <em>// getPrevButtonID defined elsewhere </em> 344 tb.setAttribute("aria-activedescendant", buttonid); 345 } else { 346 return true; 347 } 348 return false; 349 } 350} 351</script> 352 353<div role="toolbar" tabindex="0" aria-activedescendant="button1" id="tb1" 354 onkeydown="return optionKeyEvent(event);" 355 onkeypress="return optionKeyEvent(event);"> 356 <img src="buttoncut" role="button" alt="cut" id="button1"> 357 <img src="buttoncopy" role="button" alt="copy" id="button1"> 358 <img src="buttonpaste" role="button" alt="paste" id="button1"> 359</div> 360</pre> 361 362 363<h2 id="more"> Provide accessible content </h2> 364 365 366<p> 367The remaining guidelines might be familiar 368because they reflect good practices for all web content, 369not just extensions. 370</p> 371 372<h3 id="text">Text</h3> 373 374<p> 375Evaluate your use of text in your extension. 376Many people might find it helpful 377if you provide a way to increase the text size within your extension. 378If you are using keyboard shortcuts, 379make sure that they don't interfere with 380the zoom shortcuts built into Google Chrome. 381</p> 382 383<p> 384As an indicator of the flexibility of your UI, 385apply the <a href="http://www.w3.org/TR/2008/REC-WCAG20-20081211/#visual-audio-contrast-scale">200% test</a>. 386If you increase the text size or page zoom 200%, 387is your extension still usable? 388</p> 389 390<p> 391Also, avoid baking text into images: 392users cannot modify the size of text displayed as an image, 393and screenreaders cannot interpret images. 394Consider using a web font instead, 395such as one of the fonts collected in the 396<a href="http://code.google.com/apis/webfonts/">Google Font API</a>. 397Text styled in a web font is searchable, 398scales to different sizes, 399and is accessible to people using screen readers. 400</p> 401 402<h3 id="colors">Colors</h3> 403 404<p> 405Check that there is sufficient contrast between 406background color and foreground/text color in your extension. 407<a href="http://snook.ca/technical/colour_contrast/colour.html">This contrast checking tool</a> 408checks whether your background and foreground colors 409provide appropriate contrast. 410If you’re developing in a Windows environment, 411you can also enable High Contrast Mode 412to check the contrast of your extension. 413When evaluating contrast, 414verify that every part of your extension that relies on 415color or graphics to convey information is clearly visible. 416For specific images, you can use a tool such as the 417<a href="http://www.vischeck.com/vischeck/">Vischeck simulation tool</a> 418to see what an image looks like in various forms of color deficiency. 419</p> 420 421<p> 422You might consider offering different color themes, 423or giving the user the ability to customize the color scheme 424for better contrast. 425</p> 426 427<h3 id="sound">Sound</h3> 428 429<p> 430If your extension relies upon sound or video to convey information, 431ensure that captions or a transcript are available. 432See the 433<a href="http://www.dcmp.org/ciy/">Described and Captioned Media Program guidelines</a> 434for more information on captions. 435</p> 436 437<h3 id="images">Images</h3> 438 439<p> 440Provide informative alt text for your images. 441For example: 442</p> 443 444<pre> 445<img src="img.jpg" alt="The logo for the extension"> 446</pre> 447 448<p> 449Use the alt text to state the purpose of the image 450rather than as a literal description of the contents of an image. 451Spacer images or purely decorative images 452should have blank ("") alt text 453or be removed from the HTML entirely and placed in the CSS. 454</p> 455 456<p> 457If you must use text in an image, 458include the image text in the alt text. 459A good resource to refer to is the 460<a href="http://www.webaim.org/techniques/alttext/">WebAIM article on appropriate alt text</a>. 461 462<h2 id="examples">Examples</h2> 463 464<p> 465For an example that implements keyboard navigation and ARIA properties, see 466<a href="http://src.chromium.org/viewvc/chrome/trunk/src/chrome/common/extensions/docs/examples/extensions/news_a11y/">examples/extensions/news_a11y</a> 467(compare it to 468<a href="http://src.chromium.org/viewvc/chrome/trunk/src/chrome/common/extensions/docs/examples/extensions/news/">examples/extensions/news</a>). 469For more examples and for help in viewing the source code, 470see <a href="sampleshtml">Samples</a>. 471