Sam’s list already had a / shortcut. In this video, you tested the whole shopping list with the keyboard alone, added a Show only today toggle that tells a screen reader whether it’s on, and fixed a shared list snippet Sam copied from an old site. Here are the key points:
- Test with the keyboard alone. Some people can’t use a mouse, and many people using a screen reader, software that reads the page aloud, work from the keyboard too. Each press of Tab moves the focus ring, the outline around the control your next key goes to. A radio group is one stop, and the arrow keys pick inside it. Space ticks a box, and Enter on a button presses it.
- Native elements work from the keyboard for free. The browser already knows how to focus and use a real
<input>,<select>or<button>with a label. - The Accessibility tab shows what a screen reader is told. Right-click an element and choose Inspect, then open the Accessibility tab in the Elements panel, next to Styles or behind the » button when the panel is narrow. It shows the selected element’s name, its role and states such as Pressed.
- A toggle button needs
aria-pressed. It comes from ARIA, short for Accessible Rich Internet Applications, a set of attributes that tell assistive technology, like a screen reader, about an element without changing what it does. Withoutaria-pressed, the Accessibility tab showed the Show only today button’s role, button, and its name, Show only today. Nothing said whether it was on or off. - Keep it in step in
render(), and start it in the HTML. At the end ofrender(), onesetAttribute()line writes"true"or"false"ontoaria-pressed, fromtodayOnly.render()runs only after an add or a press, soaria-pressed="false"in the HTML covers the page load. - Show the state to sighted users too. If every item is for today, the list looks the same either way. An attribute selector,
[aria-pressed="true"], gives the pressed button a blue background. - Never remove the focus outline.
outline: nonelooks like a style choice, but it hides the focus ring, so a keyboard user can’t see where they are. Style:focus-visibleinstead. The browser shows it when you move with the keyboard, not when you click a button. - A
<div>with a click listener isn’t a button. A mouse can click it, but Tab skips it. Its role isgeneric, with no name. Addingrole="button"changes only what a screen reader is told. Even if the div could take the focus, Enter and Space wouldn’t click it. The browser turns those keys into a click only on a real button. Use<button type="button">, and keep a class for the look. - A placeholder isn’t a label. The gray hint disappears as soon as someone types. A screen reader still gets the name, but nothing on screen says what the box is for. A
<label>stays visible, a click on its words focuses the box, and it names the box.
Use this checklist for every page you build:
- Test with the keyboard alone.
- Use a
<button>for an action and a<label>for every box. - Style
:focus-visible, never remove the outline. - Give a toggle
aria-pressedthat follows your state.
In kitchen/index.html, the fixed snippet sits right after the Add the usual milk button, and the toggle goes between the message line and the list: