Web Development Pro | Lesson 009 | Keyboard Access and Inclusive Structure
Web Development Pro · Lesson 09 of 60
Module 1: HTML foundations
In this lesson
Prerequisites and learning outcomes
Complete lesson 8 first. This lesson builds on focus, native controls, and accessibility trees. By the end, you can audit reading order and keyboard access using a repeatable manual checklist. Plan 10–15 minutes for the core explanation and additional time for the worked practice.
Accessibility begins with usable behavior
Imagine visiting the workshop site without using a mouse. You can press Tab to move through links and form controls, Shift+Tab to go backward, and Enter or Space to activate appropriate controls. If the interface requires pointing precisely at a tiny icon or clicking a generic box that never receives focus, part of the audience cannot complete the task.
Keyboard access is one part of accessibility, alongside readable content, alternatives, contrast, zoom support, and assistive-technology compatibility. No single test covers everything. This lesson gives you a small repeatable review focused on structure and interaction so you can identify concrete barriers instead of declaring a page accessible based on appearance.
Prefer native controls
A button element already has a role, keyboard behavior, focusability, and disabled behavior. A div with a click handler has none of those by default. Adding role="button" changes how it is exposed, but it does not implement all the missing keyboard behavior. Rebuilding a native control is usually more work and creates more opportunities for mistakes.
Use links for navigation and buttons for actions. A native details element can reveal optional information without custom JavaScript. Summary provides the visible label for that disclosure. Essential information should not be hidden so deeply that visitors overlook it, but an optional explanation can fit this pattern well.
<a href="#main-content">Skip to main content</a>
<header>
<nav aria-label="Main"><a href="index.html">Home</a></nav>
</header>
<main id="main-content" tabindex="-1">
<h1>Workshop access information</h1>
<p>The fictional venue has a step-free entrance.</p>
<details>
<summary>What should I bring?</summary>
<p>Bring a notebook and the item you want to discuss.</p>
</details>
</main>
The skip link allows a keyboard user to bypass repeated navigation. Tabindex="-1" makes the main region available as a focus target without adding it to the ordinary Tab sequence. Fragment-focus behavior can vary, so test the actual skip-link journey in the browsers you support. The example leaves the skip link visible; later CSS may hide it visually until focused without removing it from use.
Keep focus order aligned with meaning
The default Tab order generally follows document order among focusable controls. Write that order so it matches the task. Avoid positive tabindex values that create a separate custom sequence; maintaining it across inserted content quickly becomes difficult. Use CSS layout without changing the meaningful reading order, because a visual rearrangement does not necessarily rearrange keyboard or screen-reader navigation.
Do not remove the browser's focus outline unless you provide a clearly visible replacement. A person should always be able to locate the active control. Focus should also not become trapped inside a component without an appropriate escape route. A simple disclosure is easier to implement reliably than a custom modal, which requires more careful focus management and will not be introduced casually here.
Some elements are intentionally not in the Tab sequence, including ordinary headings and paragraphs. This is not automatically an accessibility failure. Screen readers have additional navigation methods for headings and landmarks. Adding tabindex="0" to every paragraph can make keyboard navigation tedious by creating many unnecessary stops.
Give every control an understandable name
A visible label often supplies a control's accessible name. When a button contains only an icon, users still need a meaningful name such as “Close details.” A filename or a lone symbol may be insufficient. If visible text is present, prefer keeping the accessible name aligned with it so speech-input users can refer to what they see.
ARIA should supplement correct HTML when needed. Do not put aria-hidden="true" on a focusable control: it can remain reachable by keyboard while disappearing from the accessibility information. Similarly, hiding a form label visually should not accidentally remove the programmatic relationship. Begin with visible labels and native elements before introducing techniques whose effects you cannot yet verify.
Run a short manual review
Reload the page, set the pointer aside, and navigate from the top. Confirm that the skip link appears in the sequence, its target is useful, the disclosure opens and closes, and every link can be activated. Reverse direction with Shift+Tab. Record where focus goes rather than simply counting key presses.
Next inspect the heading outline and control names using your browser's accessibility tools when available. Zoom substantially and look for clipped text or essential content lost offscreen. A complete accessibility review also needs appropriate assistive-technology testing and human judgment. If those tools are unavailable, label those checks as unrun, not passed by assumption.
Worked practice
Worked exercise 1: Replace a fake button
Task: A div styled as a button is used to perform an action. Worked answer: use button type="button" and keep its visible action label. This supplies native focus and keyboard behavior. The actual action still needs implementation; the element choice fixes the interaction foundation.
Worked exercise 2: Remove a custom focus sequence
Task: Four navigation links have tabindex values 4, 1, 3, and 2. Worked answer: remove the positive tabindex attributes and place the links in meaningful document order. Then test both forward and backward navigation. A stable source order is easier to understand than a second numbering system.
Worked exercise 3: Audit an icon-only link
Task: A home link contains only a house SVG with no text alternative. Worked answer: provide the link with the name “Home,” preferably visible text or an appropriate accessible label. Test that the name identifies its destination. Merely making the icon larger does not supply a name.
Knowledge check
Question 1
Which element supplies native button keyboard behavior? A) A div with role="button" alone. B) A span with tabindex="0" alone. C) button. D) An anchor without href.
Check question 1: answer and explanation
Answer: C. Native buttons implement common interaction behavior that generic containers lack.
Question 2
What does tabindex="-1" generally do? A) Adds the first Tab stop. B) Allows focus targeting without normal sequential focus inclusion. C) Prevents both programmatic and sequential focus. D) Moves focus there as soon as the page loads.
Check question 2: answer and explanation
Answer: B. It is useful for deliberate focus destinations without adding an ordinary Tab stop.
Question 3
Why avoid positive tabindex values? A) They prevent links from having names. B) They create a separate fragile focus order. C) They always remove elements from the accessibility tree. D) They make controls readonly.
Check question 3: answer and explanation
Answer: B. Source changes can easily make the custom sequence confusing.
Question 4
Does role="button" alone make a div fully behave like a button? A) Yes, the role adds all native key handling. B) Yes, if the div has text. C) Yes, if the div is visually styled. D) No.
Check question 4: answer and explanation
Answer: D. ARIA describes semantics; keyboard and interaction behavior still require implementation.
Question 5
Which is a truthful test report? A) “Static labels passed, therefore all accessibility passed.” B) “Mouse navigation passed, therefore keyboard navigation passed.” C) “Keyboard journey checked; screen-reader testing not run.” D) “Native elements used, therefore no manual review is needed.”
Check question 5: answer and explanation
Answer: C. It states the evidence and its limits explicitly.