-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhow-to-not-fail-at-building-accessible-web-applications.html
666 lines (643 loc) · 22.3 KB
/
how-to-not-fail-at-building-accessible-web-applications.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
<!DOCTYPE html>
<html lang="en">
<head>
<title>How to not Fail at Building Accessible Web Applications</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description"
content="My thoughts on how to build accessible web apps.">
<link href="joy.css" rel="stylesheet">
<link href="innoq-fonts.css" rel="stylesheet">
<link href="prism-theme.css" rel="stylesheet">
<link href="slides.css" rel="stylesheet">
<style>
* {
box-sizing: border-box;
}
body {
font-family: "FFMarkWebPro", "Gill Sans", "Gill Sans MT", Calibri, "Trebuchet MS", sans-serif;;
}
body:not(.slides) h2 {
margin-top: var(--spacer-lg);
}
.slides {
--container-width: 55ch;
}
.abridged .abridge {
display: none;
}
pre {
padding: var(--spacer-sm);
margin: 0 calc(-1 * var(--spacer-sm));
overflow: auto;
max-height: 55rem;
}
figure {
border: 1px solid black;
padding: var(--spacer-md);
margin: 0 calc(-1 * var(--spacer-md));
}
blockquote {
margin: 0 0 var(--spacer-sm);
}
section {
container-type: inline-size;
}
@media (min-width: calc(80ch + 0.75rem * 2)) {
pre {
padding: var(--spacer-base);
margin: 0 calc(-1 * var(--spacer-base));
}
}
.responsive-table {
overflow: auto;
}
td {
font-size: 0.9em;
}
h3:has(code) {
line-height: 1.5;
}
</style>
<script defer src="slides.js"></script>
<script defer src="https://unpkg.com/[email protected]/prism.js"></script>
</head>
<body>
<main>
<section>
<h1>How to not Fail at Building Accessible Web Applications</h1>
<address>By <a rel="author" href="https://joyheron.com/">Joy Heron</a></address>
<p class="site-only">
This site is also available as a <a href="./how-to-not-fail-at-building-accessible-web-applications.html?slides">slideshow</a>.
</p>
</section>
<section>
<h2>Get to know your users</h2>
<ul role="list" class="possible-users">
<li><div class="emoji">👩🏻🦯</div> Users with visual impairments</li>
<li><div class="emoji">😩</div> Users with cognitive limitations</li>
<li><div class="emoji">🧏🏿</div> Users with auditory impairments</li>
<li><div class="emoji">🎨</div> Users with different color perceptions</li>
<li><div class="emoji">🏎️</div> Users with epilepsy or motion sickness</li>
<li><div class="emoji">⌨️</div> Users with physical impairments</li>
<li><div class="emoji">📱</div> Users who cannot afford expensive hardware</li>
</ul>
<style>
.possible-users {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(3rem, 1fr));
gap: var(--spacer-base);
padding: 0;
line-height: 1.25;
}
.possible-users > * {
display: grid;
grid-column: span 2;
place-items: center;
text-align: center;
border: 1px solid black;
margin-top: 0;
padding: 0.75em;
}
.possible-users .emoji {
display: block;
font-size: 5em;
line-height: 1;
}
@container (min-width: 30rem) {
.possible-users {
grid-template-columns: repeat(8, 1fr);
}
.possible-users > :nth-child(5) {
grid-column: 2 / 4;
}
}
code {
background-color: #e4e4e4;
padding: var(--spacer-xs);
}
pre code {
background-color: unset;
}
</style>
</section>
<section class="abridge">
<h3>Web Content Accessibility Guidelines (WGAG) 2.2 Principles</h3>
<ol>
<li><a href="https://www.w3.org/TR/WCAG22/#perceivable">Perceivable</a></li>
<li><a href="https://www.w3.org/TR/WCAG22/#operable">Operable</a></li>
<li><a href="https://www.w3.org/TR/WCAG22/#understandable">Understandable</a></li>
<li><a href="https://www.w3.org/TR/WCAG22/#robust">Robust</a></li>
</ol>
</section>
<section>
<h2>Step 1: Begin by building <em>and testing</em> the HTML layer</h2>
</section>
<section>
<h3>Consider multiple possible semantic HTML layers which would work as a base</h3>
<iframe src="navbar.html"></iframe>
<p>Document your thoughts as you go!</p>
<p><small><em>It may be necessary to add minimal amounts of JavaScript to test any widgets that we want to add.</em></small></p>
</section>
<section>
<h3>Add a few choice ARIA attributes to improve the accessibility of your markup</h3>
<ul>
<li>Add a descriptive <code>aria-label</code> to each <code>ul</code> unordered list</li>
<li>Indicate link to current page with <code>aria-current="page"</code></li>
<li class="abridge">Add <code>role="list"</code> to all lists where we are going to change the <code>display</code> property with CSS
(See <a href="https://www.scottohara.me/blog/2019/01/12/lists-and-safari.html">Blog Post on "Fixing Lists" by Scott O'Hara</a>)
</li>
</ul>
</section>
<section>
<h3>Example: HTML-only Navbar</h3>
<iframe src="navbar-example.html?nostyle&noscript"></iframe>
<p><a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/details"><code><details></code></a> elements are a great HTML-only fallback!</p>
</section>
<section>
<h3>Add <a href="https://webaim.org/techniques/skipnav/">skip links</a> to improve navigation for keyboard users</h3>
</section>
<section>
<h3>What are all of the points that we need to consider to make the HTML of a website accessible?</h3>
<iframe src="https://responsibleweb.app/#Accessible-Web-Design"></iframe>
</section>
<section>
<h2>Step 2: Add a CSS layer to implement the design</h2>
</section>
<section>
<h2>Style skip links so that they are hidden except when focused</h2>
<pre class="language-css" aria-label="CSS Code to style a skip link"><code>.skip-link {
/* ...styles for skip link... */
&:not(:focus) {
@extend %sr-only;
}
}</code></pre>
</section>
<section>
<h3>Connect CSS rules to ARIA attributes to ensure HTML is correct</h3>
<pre class="language-css" aria-label="CSS Code used to enforce the accessibility of the current link in the HTML markup"><code>/* Use CSS rules to enforce the accessibility of the current link
within the navbar. If it is visually correct, it will also be
semantically correct. */
a[aria-current='page'] {
text-decoration: underline;
text-decoration-color: $active-color;
text-decoration-thickness: 3px;
text-underline-offset: $spacer-xs;
}
</code></pre>
<p>See <a href="https://adrianroselli.com/2021/06/using-css-to-enforce-accessibility.html">Blog Post on "Using CSS to Enforce Accessibility" by Adrian Roselli</a></p>
</section>
<section class="abridge">
<h3>Add rule only removing list styles when we have added a <code>role</code> attribute to a list</h3>
<pre class="language-css" aria-label="CSS code to remove list styles from an HTML list with the role attribute"><code>/* Removing `list-style` attributes causes the list to no longer
appear as a list in the accessibility tree. As a workaround, this
only removes the list styling once the ARIA `role="list"` has
been set to reinstate the list semantics for the list. */
ul[role='list'],
ol[role='list'] {
list-style: none;
list-style-type: none;
}</code></pre>
<p>(See <a href="https://www.scottohara.me/blog/2019/01/12/lists-and-safari.html">Blog Post on "Fixing Lists" by Scott O'Hara</a>)</p>
</section>
<section>
<h3>Define CSS properties to tweak the theme based on CSS media features</h3>
<pre class="language-css" aria-label="CSS code defining CSS properties based on CSS media features"><code>@media (prefers-reduced-motion: no-preference) { /* ❤️ 🏎️ */
--grid-row-transition: grid-template-rows #{$speed} #{$easing};
--visibility-transition: visibility #{$speed} #{$easing};
}
@media (forced-colors: active) { /* ❤️ 🎨 */
--forced-colors-link-border-width: 0;
--forced-colors-action-margin: #{$navbar-focus-outline-width};
--forced-colors-link-decoration: underline;
--forced-colors-navbar-toggler-width: 10rem;
}
@media (pointer: fine) { /* ❤️ 📱 vs. 🖱️ */
--pointer-fine-navbar-meta-font-size: #{$small-font-size};
--pointer-fine-navbar-meta-spacer: #{$spacer-xs * 0.5};
}
</code></pre>
</section>
<section class="abridge">
<h3>Use defined CSS properties instead of hard coded values</h3>
<pre class="language-css" aria-label="CSS code defining CSS properties based on CSS media features"><code>&[data-expanded] {
grid-template-rows: var(--main-navigation-grid-template-rows);
transition: var(--grid-row-transition);
.navigation-links,
.navigation-meta {
overflow: hidden;
min-height: 0;
transition: var(--visibility-transition);
visibility: var(--main-navigation-menu-visibility);
}
}
</code></pre>
<p><em>Note that it is <strong>finally</strong> possible to animate <code>height: auto;</code> by animating the <code>grid-template-rows</code> property!
<br>(See <a href="https://nemzes.net/posts/animating-height-auto/">Blog Post on "Animating height: auto" by Nelson Menezes</a>)</em></p>
</section>
<section>
<h3>Important Media Queries</h3>
<ul>
<li>
<a href="https://developer.mozilla.org/en-US/docs/Web/CSS/@media/prefers-reduced-motion">
<strong><code>prefers-reduced-motion</code></strong></a> —
<strong>ALWAYS</strong> reduce motion when a user requests it to prevent possible
epileptic event or motion sickness 🏎️
</li>
<li>
<a href="https://developer.mozilla.org/en-US/docs/Web/CSS/@media/forced-colors">
<strong><code>forced-colors</code></strong></a>,
<a href="https://developer.mozilla.org/en-US/docs/Web/CSS/@media/prefers-contrast">
<strong><code>prefers-contrast</code></strong></a>, and
<a href="https://developer.mozilla.org/en-US/docs/Web/CSS/@media/prefers-color-scheme">
<strong><code>prefers-color-scheme</code></strong>
</a> indicate different user color needs 🎨
</li>
<li>
<a href="https://developer.mozilla.org/en-US/docs/Web/CSS/@media/pointer">
<strong><code>pointer</code></strong></a> and
<a href="https://developer.mozilla.org/en-US/docs/Web/CSS/@media/hover">
<strong><code>hover</code></strong></a> can indicate usage of mobile devices 📱
</li>
</ul>
</section>
<section>
<h3>Use a <a href="https://webaim.org/resources/contrastchecker/">color contrast checker</a> to ensure that all color combinations pass at least the WCAG 2.0 AA level</h3>
</section>
<section>
<h3>Ensure focus Styles have sufficient contrast!</h3>
<p>With <code>focus-visible</code> we can turn off focus rings for users who are navigating with a mouse.</p>
<pre class="language-css" aria-label="CSS Code for removing focus styles when focus is not visible"><code>/* double ring for focus to improve contrast */
&:focus {
border-color: $navbar-link-hover-color;
outline: 2px solid $navbar-lightened-bg;
}
/* Remove outline styles when keyboard not being used */
&:focus:not(:focus-visible) {
border-color: transparent;
outline: none;
}</code></pre>
</section>
<section>
<h3>Example: Navbar with only HTML and CSS</h3>
<div class="frame-wrapper">
<iframe class="mobile" src="navbar-example.html?noscript"></iframe>
<iframe class="desktop" src="navbar-example.html?noscript"></iframe>
</div>
<style>
.frame-wrapper {
display: flex;
gap: var(--spacer-sm);
min-height: 30rem;
overflow: auto;
}
.frame-wrapper .mobile {
min-width: 20rem;
max-width: 30rem;
}
.frame-wrapper .desktop {
min-width: 925px;
}
@media (min-width: calc(80ch + 0.75rem * 2)) {
.frame-wrapper {
margin: 0 calc(-1 * (80vw - var(--container-width)) / 2);
}
}
</style>
</section>
<section>
<h2>Step 3: Add JavaScript to improve the design</h2>
</section>
<section>
<h3>Progressively-enhance <code><details></code> elements to become a toggle button using <code>aria-expanded</code></h3>
<p>
<small><em>
needed here "only" to add animation to submenu toggle and hover
</em></small>
</p>
<div class="html-enhancement">
<pre aria-label="HTML for submenu using a details element"><code class="language-markup"><sub-menu>
<details>
<summary>
...
</summary>
<ul role="list"
aria-label="...">
...
</ul>
</details>
</sub-menu>
</code></pre>
<span>➡️</span>
<pre aria-label="HTML after sub-menu has activated the progressive enhancement"><code class="language-markup"><sub-menu>
<button type="button"
aria-expanded="false">
...
</button>
<div>
<ul role="list"
aria-label="...">
...
</ul>
</div>
</sub-menu>
</code></pre>
</div>
<style>
@media (min-width: 30rem) {
.html-enhancement {
display: flex;
flex-wrap: wrap;
align-items: center;
}
.html-enhancement > span {
margin: 0 calc(1.5 * var(--spacer-base));
}
.html-enhancement > pre {
flex-grow: 1;
}
}
</style>
<a class="presentation-only" href="./how-to-not-fail-at-building-accessible-web-applications.html#js-submenu" target="_blank">Code for <code>sub-menu</code> custom element</a>
</section>
<section class="site-only">
<h4 id="js-submenu">Code for <code>sub-menu</code> custom element</h4>
<pre class="language-javascript " aria-label="JavaScript Code to progressively enhance details element"><code>export default class Submenu extends HTMLElement {
connectedCallback() {
let summary = this.querySelector('summary')
let ul = this.querySelector('ul')
if (!summary && !ul) {
return
}
// With our method of animating the collapsing/expanding of
// the menu, it is necessary to wrap the content of the menu
// in a `<div>`
this.innerHTML = `<button type="button" aria-expanded="false">${summary.innerHTML}</button><div>${ul.outerHTML}</div>`
this.button.addEventListener('click', () => this.toggle())
this.navigation.addEventListener('submenu-toggle', (ev) => {
if (ev.detail && ev.detail.expanded &&
ev.target !== this.button) {
if (this.button.getAttribute('aria-expanded') === 'true') {
this.toggle(false)
}
}
})
this.toggle(false)
}
toggle(expanded = !(this.button.getAttribute('aria-expanded') === 'true')) {
let button = this.button
button.setAttribute('aria-expanded', expanded)
button.dispatchEvent(new CustomEvent('submenu-toggle', { detail: { expanded }, bubbles: true }))
}
get navigation() {
return this.closest('ul')
}
get button() {
return this.querySelector('button')
}
get div() {
return this.querySelector('div')
}
get ul() {
return this.querySelector('ul')
}
}
customElements.define('sub-menu', Submenu);</code></pre>
</section>
<section>
<h3>Hook CSS styles for showing/hiding the menu to the <code>aria-expanded</code> attribute</h3>
<p>This ensures that the attribute is correctly defined on the <em><strong>button</strong></em></p>
<pre aria-label="truncated CSS Code for expanding/collapsing submenu"><code class="language-css">sub-menu {
button[aria-expanded='false'] + div {
/* styles for collapsed submenu */
}
button[aria-expanded='true'] + div {
/* styles for expanded submenu */
}
}
</code></pre>
<a class="presentation-only" target="_blank" href="./how-to-not-fail-at-building-accessible-web-applications.html#css-expand">Full CSS Code for collapsing and expanding submenu</a>
</section>
<section class="site-only">
<h4 id="css-expand">Full CSS Code for collapsing and expanding submenu</h3>
<pre class="language-css" aria-label="full CSS Code for expanding/collapsing submenu"><code>sub-menu {
div {
display: grid;
overflow: hidden;
grid-template-rows: var(--submenu-grid-template-rows);
transition: var(--grid-row-transition);
}
ul {
min-height: 0;
margin-bottom: $spacer-xs;
transition: var(--visibility-transition);
visibility: var(--submenu-visibility);
}
button[aria-expanded='false'] + div {
--submenu-grid-template-rows: 0fr;
--submenu-visibility: hidden;
}
button[aria-expanded='true'] + div {
--submenu-grid-template-rows: 1fr;
--submenu-visibility: visible;
}
}
</code></pre>
</section>
<section>
<h3>Example: Navbar with HTML, CSS and JavaScript</h3>
<div class="frame-wrapper">
<iframe class="mobile" src="navbar-example.html"></iframe>
<iframe class="desktop" src="navbar-example.html"></iframe>
</div>
</section>
<section>
<h3>When else may I <del>need</del> <ins>want</ins> JavaScript?</h3>
</section>
<section class="abridge">
<h4>If something changes on page, it is necessary to <em>announce</em> this to the user</h4>
<ul>
<li>
Create an HTML element with <code>role="status"</code> and <code>aria-live="polite"</code>
and update it to announce changes for assistive technologies.
</li>
<li>
it's usually necessary for the element to already exist before its content is changed in order for
its content to be announced
</li>
<li>
<strong>🔥 Tip:</strong> integrate area for announcements into the visual design to help all users,
not only users of assistive technology
</li>
</ul>
</section>
<section>
<h4><a href="https://www.w3.org/TR/using-aria/#firstrule">First rule of ARIA</a></h4>
<blockquote>
If you <em>can</em> use a native HTML element or attribute with the semantics and behavior you require
<strong>already built in</strong>, instead of re-purposing an element and adding an ARIA role, state
or property to make it accessible, <strong>then do so.</strong>
</blockquote>
</section>
<section>
<h4>Know your widgets</h4>
<div class="responsive-table">
<table>
<thead>
<tr>
<th>Widget</th>
<th>Pay attention to...</th>
</tr>
</thead>
<tbody>
<tr>
<td>Disclosure Widget</td>
<td>
<code>aria-expanded</code> is an attribute on the <em>button</em>, the expanded content should directly
follow the button that expands it
</td>
</tr>
<tr>
<td>
<a href="https://inclusive-components.design/tabbed-interfaces/">Tabbed Interfaces</a></td>
<td>
It shouldn't look like tabs unless it behaves like tabs. Tab selection should occur by
<em>arrow keys</em> not the TAB-key. (Most tab components don't do this correctly)
</td>
</tr>
<tr>
<td>Dialogs</td>
<td>
Need to implement focus trapping and make sure ESC-key shuts the dialog
(usually the user also wants to close it by clicking outside of the dialog).
It's also <strong>critical</strong> that there is a focussable close button within the dialog.
<strong>Use <code><dialog></code> element.</strong>
</td>
</tr>
<tr>
<td>
<a href="https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/listbox_role">Listboxes</a>
</td>
<td>
Options in list should be able to be selected with arrow keys
(prefer using a built-in <code><select></code>)
</td>
</tr>
<tr>
<td>
<a href="https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/ARIA_Live_Regions">ARIA live regions</a>
</td>
<td>
Change content of an <code>aria-live="polite"</code> region to announce changes to user.
</td>
</tr>
</tbody>
</table>
</div>
</section>
<section class="abridge">
<h2>Accessibility Evaluation Tooling</h2>
<figure>
<blockquote cite="https://webaim.org/projects/million/">
95.9% of home pages had detected <a href="https://webaim.org/standards/wcag/checklist">WCAG 2</a> failures.
This improved slightly from 96.3% in 2023. Over the last 5 years, the pages with detectable WCAG failures
have decreased by only 1.9% from 97.8%. These are only automatically detected errors that align with WCAG
conformance failures with a high level of reliability which suggests that the rate of full WCAG 2 A/AA
conformance was certainly lower.
</blockquote>
<figcaption>WebAim — <cite>The WebAIM Million</cite></figcaption>
</figure>
</section>
<section>
<h2>How to test your web application</h2>
<table>
<thead>
<tr>
<th>For a user with...</th>
<th>...test with...</th>
</tr>
</thead>
<tbody>
<tr>
<td>
visual impairments 👩🏻🦯
</td>
<td>
screenreaders
</td>
</tr>
<tr>
<td>
cognitive limitations 😩
</td>
<td>
200% zoom, user tests
</td>
</tr>
<tr>
<td>
auditory impairments 🧏🏿
</td>
<td>
sound turned off<br>
<small>(ensure transcripts, closed captions available)</small>
</td>
</tr>
<tr>
<td>
different color perceptions 🎨
</td>
<td>
color contrast checkers, color blindness simulators
</td>
</tr>
<tr>
<td>
epilepsy or motion sickness 🏎️
</td>
<td>
<strong><code>prefers-reduced-motion: reduce</code></strong> activated!
</td>
</tr>
<tr>
<td>
physical impairments ⌨️
</td>
<td>
keyboards
</td>
</tr>
<tr>
<td>
inexpensive hardware 📱
</td>
<td>
cheap mobile devices
</td>
</tr>
</body>
</table>
<p>
<em>Automate some checks with <a href="https://wave.webaim.org/">WAVE web accessibility evaluation tool</a> or
<a href="https://accessibilityinsights.io/">Accessibility Insights</a>.</em>
</p>
</section>
<section class="abridge">
<h2>Next Steps</h2>
<p>
Subscribe to a newsletter like <a href="https://a11yweekly.com/">A11y Weekly</a> to learn more
about accessibility and hear stories from different user groups!
</p>
</section>
<section class="presentation-only">
<p><strong>Thank you!</strong></p>
<p>
The content of this presentation is also available as a
<a href="./how-to-not-fail-at-building-accessible-web-applications.html" target="_blank">
microsite.
</a>
</p>
</section>
</main>
</body>
</html>