Volume 2 Exercises: The Web FrontendPractice for Volume 2
0 / 0

Workbench / Volume 2 Exercises: The Web Frontend

V2·20

Accessibility

Exercises for Volume 2, chapter 20: who accessibility serves, WCAG 2.2 and POUR, semantic HTML, accessible names, labels and descriptions, keyboard navigation and focus management, target size, screen readers, contrast, zoom and reflow, reduced motion, ARIA roles, states and live regions, the widget patterns (dialog, tabs, menu, tree, grid, combobox, tooltip, accordion) and testing. 9 theory questions, 9 programming exercises, 3 cumulative projects, the concepts the chapter leaves out, and 5 senior-level exercises.

32 exercises · ~13 min to read
Updated Suggest a correction

Start here: how this chapter's exercises work

Same four sets and the same locking. Accessibility exercises need three tools: the browser's accessibility tree (DevTools' Accessibility pane, or Playwright's ariaSnapshot()), axe-core (4.10.2 here) and your own keyboard and a screen reader (NVDA on Windows, VoiceOver on macOS and iOS, TalkBack on Android). All outputs quoted are real (Chromium 153). Two of them correct common beliefs: P2's title attribute doesn't name a button that has text content, and P5 shows that a role="button" div with tabindex still ignores Enter and Space.

The chapter's lab measured what axe catches on the lunch-order page (five of nine problems), the contrast formula, <dialog> vs a div modal, reflow at 320 px and reduced motion; the exercises build on those without repeating them.

Coverage map.

Chapter component Exercises
who accessibility serves; WCAG and POUR; law T1
semantic HTML first T2, P1
accessible names, labels and descriptions T3, P2
keyboard navigation, focus management T4, P5, P6
target size and pointer accessibility T4, P3
screen readers and the accessibility tree T5, P4
contrast, forced colours T6, P7
zoom, resize, reflow, text spacing T6, P8
reduced motion and flashing T6
ARIA: roles, states, properties, the first rule T7, P3
live regions T8, P9
widget patterns: dialog, tabs, menu, tree, grid, combobox, tooltip, accordion T9, P6
testing accessibility T5, P3, C2

Theory

T1. Who, why and WCAG

  1. List the groups accessibility serves (permanent, temporary and situational disabilities) with one TiffinBox example each: blind, low vision, colour blind, deaf, motor, tremor, cognitive and learning, vestibular, a broken wrist, bright sunlight, a toddler on one arm, slow 3G, an older user.
  2. Explain POUR (perceivable, operable, understandable, robust), the A/AA/AAA levels, and what WCAG 2.2 added (focus not obscured, dragging movements, target size minimum, consistent help, redundant entry, accessible authentication).
  3. Which laws and standards apply to a company selling in India, the EU and the US (the Rights of Persons with Disabilities Act 2016 and GIGW, the European Accessibility Act from June 2025 with EN 301 549, the ADA and Section 508)? Why is "we'll do accessibility later" expensive?

T2. Semantic HTML first

  1. For each, give the semantic element and what it provides for free: a clickable "Pay" div, a "Menu" that navigates to /menu, a clickable dish card, a group of radio-like delivery slots, a page section with a heading, a list of orders, a table of nutrition values, a site footer, a search form.
  2. Why do landmarks (header, nav, main, aside, footer, search) and headings matter so much to screen-reader users? What does a good heading outline for the kitchen page look like?
  3. Explain why <a> vs <button> matters (navigation vs action), including for middle-click, "open in new tab", the back button and screen readers' link lists.

T3. Accessible names and descriptions

  1. State the accessible name computation order (aria-labelledby, aria-label, native label/alt/legend/caption, content, title/placeholder as a last resort) and apply it to P2's buttons. Why did <button title="Search menu">🔍</button> get the name "🔍", not "Search menu"?
  2. Why must the accessible name contain the visible label (WCAG 2.5.3 Label in Name)? P2's <button aria-label="Add to cart">Add Paneer thali</button> gets the name "Add to cart": what breaks for voice-control users?
  3. Name vs description: when do you use aria-describedby (hints, errors, format requirements), and why should names be short?

T4. Keyboard, focus and pointer

  1. What must keyboard users be able to do (WCAG 2.1.1, 2.1.2 no keyboard trap, 2.4.3 focus order, 2.4.7 focus visible, 2.4.11 focus not obscured)? What's the role of tabindex="0", tabindex="-1" and why is a positive tabindex almost always a bug?
  2. Focus management in a single-page app: where should focus go after (a) a client-side route change, (b) opening and closing a dialog (the lab's experiment 3), (c) deleting an item from a list, (d) a form submission with errors, (e) "Load more" results?
  3. Target size: WCAG 2.5.8 requires 24 × 24 CSS px (or enough spacing); P3's axe run flagged two 16 × 16 buttons. What else matters for pointer users (pointer cancellation 2.5.2, dragging alternatives 2.5.7, motion actuation, hover-only content)?

T5. Screen readers and the accessibility tree

  1. Explain the accessibility tree: what browsers derive from the DOM (role, name, description, state, value, relationships), and how screen readers consume it through platform APIs (UIA, NSAccessibility/AX, ATK/AT-SPI, Android's AccessibilityNodeInfo).
  2. P4 compared hiding techniques. Which remove content from the accessibility tree, which from the Tab order, and which from both? Why is aria-hidden="true" on a focusable element a bug (axe's aria-hidden-focus)?
  3. Explain screen-reader modes (browse/virtual cursor vs focus/forms mode), why custom widgets must handle keys themselves, and what a basic test routine with NVDA or VoiceOver looks like.

T6. Visual: contrast, forced colours, zoom, spacing, motion

  1. WCAG contrast thresholds: 4.5:1 for normal text, 3:1 for large text (24 px, or 18.66 px bold), 3:1 for UI component boundaries, focus indicators and meaningful graphics (1.4.11). Using the lab's numbers, which TiffinBox colours need changing, and how do you keep the brand orange?
  2. P7 found that under Windows forced colours (High Contrast), a focus ring made with box-shadow disappeared entirely while an outline ring survived, and a dark background-colour icon turned white. Explain forced-colours mode, and how to design for it (outline with transparent fallback, forced-color-adjust, @media (forced-colors: active), system colours like CanvasText, Highlight).
  3. Zoom and reflow (1.4.4 resize text 200%, 1.4.10 reflow at 320 CSS px), text spacing (1.4.12, P8), reduced motion (2.3.3) and flashing (2.3.1, three flashes per second): one design rule for each.

T7. ARIA: what it is, and the rules

  1. State the five rules of ARIA use (no ARIA if a native element works; don't change native semantics unless you must; all interactive ARIA controls must be keyboard usable; don't use role="presentation" or aria-hidden on focusable elements; interactive elements must have an accessible name). Why does WebAIM's Million report find pages with ARIA have more errors on average?
  2. P3's axe run on a page of ARIA traps flagged five rules: aria-hidden-focus, aria-valid-attr-value (aria-expanded="maybe"), autocomplete-valid, list (a div inside ul), target-size. It did not flag a role="button" div without tabindex, a <button> nested in a link, duplicate IDs referenced by aria-labelledby, alt="image" or "Click here" links. Explain why each miss is hard for a tool, and how you'd catch them.
  3. Explain roles, states and properties with examples: aria-expanded, aria-pressed, aria-selected, aria-checked, aria-current, aria-controls, aria-haspopup, aria-invalid, aria-required, aria-busy. Which have native HTML equivalents you should prefer?

T8. Live regions and status messages

  1. Explain aria-live="polite" vs "assertive", role="status", role="alert", role="log", aria-atomic and aria-relevant. Which do you use for: "Added to cart", a form error after submit, "Your order is out for delivery", a new chat message, a session-expiry warning?
  2. Why must a live region exist in the DOM (and in the accessibility tree) before its content changes? What are the common live-region failures (inserting the region with its message, display: none toggles, announcing too much, duplicate announcements)?
  3. WCAG 4.1.3 Status Messages: what counts as a status message, and why shouldn't you move focus to announce one?

T9. Widget patterns

  1. For each APG pattern, give the keyboard model and the key ARIA: dialog (modal), tabs, menu button and menu, tree, grid, combobox (with listbox popup), tooltip, accordion (disclosure).
  2. Explain the roving tabindex and aria-activedescendant techniques for composite widgets: when do you use each?
  3. Many things built as "menus" (role="menu") shouldn't be. When is a site navigation dropdown a menu, and when a disclosure with links? Why do tooltips often fail (touch, hover-only, essential info hidden)?

Programming exercises

P1. Rebuild a div-soup component semantically

Take this "dish card" and rebuild it with semantic HTML, without changing its look: <div class="card" onclick="openDish(7)"><div class="title">Paneer thali</div><div class="price">₹180</div><div class="veg">●</div><div class="btn" onclick="add(7)">Add</div><div class="fav" onclick="fav(7)">♡</div></div>. Then Tab through it, compare the accessibility tree before and after, and run axe.

P2. The accessible name computation, measured

Build a page of controls whose names come from different sources, and record the names the browser computes (Playwright's locator.ariaSnapshot() or DevTools' Accessibility pane): an icon button with an aria-hidden SVG; with aria-label; with both aria-labelledby (two spans) and aria-label; with title and emoji content; a <label for> input; a placeholder-only input; a link wrapping an alt="" image; a link wrapping an image with alt; a button with visually hidden text; a button whose aria-label differs from its visible text.

P3. axe in CI, and what it misses

Add @axe-core/playwright to your Playwright tests: run axe on the home, kitchen, cart and checkout pages (and with the cart drawer and a dialog open), fail the build on violations at WCAG 2.2 AA, and allow documented exceptions. Then build a "traps" page with known problems and record which axe reports.

P4. Hiding things correctly

Put nine buttons on a page hidden in different ways: display: none, visibility: hidden, opacity: 0, aria-hidden="true", inside an inert container, the hidden attribute, off-screen positioning, and the sr-only clip pattern. Record, for each, whether it's in the accessibility tree (use CDP's Accessibility.getFullAXTree, not only Playwright's snapshot) and in the Tab order. Then fix a real bug: an off-canvas mobile menu hidden with transform: translateX(-100%) whose links are still tabbable.

P5. Keyboard behaviour of buttons, div buttons and link buttons

Make three "Pay" controls: a <button>, a <div role="button" tabindex="0"> and an <a href="#" role="button">, each with a click handler. Focus each and press Enter, then Space, and record what fires. Then write the minimum JavaScript to make the div behave like a button, and argue why you shouldn't.

P6. A keyboard-accessible tabs component with tests

Build the menu category tabs (Thalis, Biryanis, Desserts) following the APG tabs pattern with roving tabindex and automatic activation. Write Playwright tests: Tab lands on the selected tab; Right/Left wrap around; Home/End; the next Tab goes into the panel; aria-selected and hidden panels stay in sync; the URL hash reflects the tab; screen-reader announcement checked manually with NVDA or VoiceOver.

P7. Contrast and forced colours across your design tokens

Write a script that computes contrast (the lab's formula) for every text/background pair in your design tokens and every state (default, hover, focus, disabled, error), failing below 4.5:1 for text and 3:1 for UI boundaries and focus indicators. Then emulate forced colours (forced_colors='active' in Playwright) and check focus rings, button borders and icons.

P8. Reflow, zoom and text spacing

Test the kitchen page at 320 CSS px wide (400% zoom equivalent), at 200% text-only zoom (Firefox's "Zoom text only" or a root font-size: 200%), and with the WCAG 1.4.12 text-spacing overrides (line-height 1.5, paragraph spacing 2em, letter-spacing 0.12em, word-spacing 0.16em). Detect horizontal scrolling, clipped text (scrollHeight > clientHeight) and overlapping elements automatically.

P9. Live regions that actually announce

Implement three status messages: "Added Paneer thali to cart" (polite), a search result count after typing pauses, and "Connection lost, retrying" when offline. Make the regions exist at load, handle repeated identical messages, and test with NVDA or VoiceOver. Also write an automated test that checks the region's text changes (since you can't test speech directly).

Cumulative projects (chapters so far: Volume 1, and Volume 2's 00, 12–20)

C1. An accessible checkout flow

Build TiffinBox's checkout (address, delivery slot, payment method, review, place order) to WCAG 2.2 AA: semantic forms with persistent labels and autocomplete (chapter 13), error summaries and inline errors with aria-describedby, no redundant entry (3.3.7: reuse the saved address), accessible authentication for OTP (3.3.8: allow paste and autocomplete="one-time-code"), focus management between steps, a step indicator with aria-current="step", live status for "Placing order…", target sizes of at least 44 px on mobile, reduced-motion-aware transitions, and a confirmation page that moves focus to its heading. Verify with axe in CI, keyboard-only tests, and a screen-reader walkthrough on Android (TalkBack) and iOS (VoiceOver).

Combines: forms and validation (ch 13), CSS layout and tokens (ch 14), JavaScript and TypeScript (ch 15, 16), browser APIs (ch 17), idempotent order submission (Volume 1, ch 11; ch 13's P8) and this chapter.

C2. An accessibility test strategy for the TiffinBox frontend

Design the layered strategy: lint rules (eslint-plugin-jsx-a11y or Angular's template rules), component tests with role-based queries, axe in unit tests (jest-axe/vitest-axe) and in Playwright per page and state, visual regression for focus states and forced colours, keyboard journey tests, manual screen-reader test scripts per release, an accessibility statement and feedback channel, and testing with disabled users. Assign owners and CI gates, and estimate the cost.

Combines: testing and CI ideas from Volume 1 (ch 01, 10), this volume's tooling and component chapters (ch 14–17), and this chapter's testing section.

C3. An accessible, performant, real-time order tracker

Build the order-tracking page with live updates over SSE (chapters 17 and 19): a status timeline (Ordered → Preparing → Out for delivery → Delivered) as an ordered list with aria-current, live announcements of status changes (polite, not every location ping), an accessible map alternative (text: "Rider is 1.2 km away, about 6 minutes"), a "Call rider" button with a 44 px target, reduced-motion handling for the rider marker animation, offline status ("Connection lost, retrying") and good Core Web Vitals (no layout shift when updates arrive). Test with axe, keyboard and a screen reader.

Combines: real-time transports and caching (ch 19), Web APIs (ch 17), browser rendering and Core Web Vitals (ch 18), CSS (ch 14) and this chapter.

What the chapter leaves out

Accessible media: captions, transcripts and audio description

Video and audio content needs captions (WCAG 1.2.2, synchronised text of speech and important sounds, in WebVTT via <track kind="captions">), transcripts (for audio-only content like podcasts), and audio description (1.2.5 AA: narration of important visual information, or an extended text alternative). Auto-generated captions are a start but need human correction, especially for Indian languages and names. Media players must be keyboard-operable with labelled controls, and autoplaying audio needs a pause (1.4.2). TiffinBox's "how it's made" kitchen videos and voice notes from riders fall under these rules.

Cognitive accessibility and plain language

WCAG covers cognitive needs only partly; the W3C's Making Content Usable for People with Cognitive and Learning Disabilities (COGA) adds guidance: plain language (short sentences, common words, a reading age around 12–14), consistent navigation and naming, clear headings, visible labels, error prevention and easy undo, no time pressure, avoiding dark patterns (fake urgency timers, confirmshaming), and support for memory (don't make users remember codes or earlier steps). Writing UI copy in Hindi, Telugu and other languages with the same principles matters for TiffinBox's audience, alongside lang attributes on mixed-language content so screen readers switch voices.

Mobile accessibility and native platform features

Mobile web users rely on TalkBack (Android) and VoiceOver (iOS) gestures (swipe to move, double tap to activate, rotor), Switch Access, Voice Access, system font scaling (which affects web content via browser text-size settings), and orientation (1.3.4: don't lock to portrait). Touch targets, gesture alternatives (2.5.1: no multi-finger or path gestures without single-pointer alternatives) and avoiding hover dependence matter most. Native apps use platform APIs (Android's contentDescription, iOS's accessibilityLabel), covered in the mobile volume.

Accessibility overlays and why to avoid them

Overlay widgets (JavaScript plugins promising "instant ADA compliance" with an accessibility toolbar) are widely criticised by disabled users and experts: they don't fix underlying semantics, can interfere with screen readers and users' own settings, sometimes add new barriers, and have not protected companies from lawsuits (some lawsuits cite them; the US FTC fined one vendor in 2025 for misleading claims). The Overlay Fact Sheet signed by hundreds of practitioners recommends against them. Fix the code and design system instead; users already have the tools they need on their devices.

Conformance reporting and accessibility statements

Organisations document accessibility with an accessibility statement (conformance level, known issues, contact for feedback, date of review: required for public sector bodies in the EU and India's GIGW) and, for B2B and government sales, a VPAT/ACR (Voluntary Product Accessibility Template / Accessibility Conformance Report) listing each WCAG criterion as Supports, Partially Supports or Does Not Support with remarks. Writing one honestly requires an audit; it becomes a procurement requirement when TiffinBox sells corporate meal plans to large employers and government offices.

Senior exercises

S1. Set up accessibility in a design system

TiffinBox's design system has 40 components, most built by different teams with varying quality. Plan how to make the system the main lever for accessibility: an audit of each component, priorities, the API decisions that prevent misuse (e.g. icon buttons that require a label prop), documentation, tests and a rollout to product teams.

S2. Review a pull request for accessibility

A PR adds a "dish customisation" popover: a <div> that appears on hover over a dish, with spice-level options as coloured circles (green/yellow/red, onclick on <span>s), a "Done" <div> button, outline: none on everything, aria-label="popup" on the container, a 300 ms slide-in animation, and an aria-live="assertive" region announcing "Customisation updated" on every change. Write the review comments, ranked by severity, with suggested code.

S3. Make the case for accessibility to leadership

Leadership sees accessibility as a compliance cost. Write a one-page proposal for an accessibility programme at TiffinBox: the business, legal and engineering case, the plan for the next two quarters, the investment, the metrics, and what you'll stop doing.

S4. Investigate a complaint from a screen-reader user

A customer writes: "I use TalkBack. When I add a dish, nothing happens, and then I can't find the cart. Checkout says 'error' but not what's wrong." Plan how you'll reproduce, diagnose and fix this, and how you'll respond to the customer.

S5. Teach accessibility with one component

Prepare a 15-minute team session using one component, the "Veg only" filter toggle, to teach semantics, names, states, keyboard, focus, contrast, forced colours, announcements and testing. Outline the session, the live demos, and the five rules people should leave with.