🎉 75% of content is free forever — Unlock Premium from $10/mo →
CW
NEWSLIVESearch All Content
đŸ’ŧ Servicesâ„šī¸ Aboutâœ‰ī¸ ContactView Pricing Plansfrom $10

HTML Accessibility: ARIA, Keyboard, and Screen Readers

Web FoundationsđŸŸĸ Free Lesson

HTML Accessibility

Accessibility is not a feature toggle bolted on before launch; it is the discipline of making interfaces perceivable, operable, and understandable by everyone — including the estimated one in four adults living with a disability, people using older hardware, and anyone temporarily constrained by a broken wrist, a bright train platform, or a spotty connection. The technical bar is lower than most teams fear. Native HTML, used thoughtfully, covers the majority of the work, and ARIA fills the genuine gaps rather than decorating everything in sight.

This lesson teaches the two core skills: reading a page the way assistive technology does, and reaching for the smallest ARIA addition that fixes a real problem.

How Screen Readers Consume a Page

A screen reader does not see your layout — it reads a structured accessibility tree derived from your markup: roles, names, states, and relationships. Users navigate it with quick strategies rather than linear reading. Landmark jumps (banner, main, navigation) move between page regions. Heading lists display the outline. Link and button lists gather every action in one place. Tables announce row and column headers as the user arrows between cells.

Every one of those strategies depends on information you provide in HTML. Semantic elements generate the roles automatically. The accessible name of a control comes from its label text, aria-label, or aria-labelledby — and an unnamed button reads as just "button." Relationships (this input belongs to that error, this section belongs to that heading) come from attributes such as aria-describedby and aria-labelledby. When those signals are missing, users get soup.

ARIA's First Rule: Do Not Use ARIA

The ARIA spec opens with its own first rule: if a native HTML element or attribute provides the semantics and behavior you need, use it and do not add ARIA. A div with role="button", tabindex="0", and handlers for Enter and Space is a pale imitation of the real button element, which already ships all three plus focus styles and disabled behavior.

The rule exists because ARIA alters only the accessibility tree, never actual behavior. role="checkbox" on a div announces as a checkbox but does not toggle on click; aria-expanded on a non-collapsible element announces a state that never changes. Native HTML gives you the semantics and the wiring. Reach for ARIA when the design genuinely has no native equivalent — a custom tree view, a combobox with filtering, a disclosure with bespoke styling that the details element cannot support.

Roles, States, and Properties

ARIA falls into three families. Roles declare what an element is (role="dialog", role="tablist", role="alert"). States describe conditions that change over time (aria-expanded, aria-checked, aria-disabled, aria-selected). Properties describe relationships that persist (aria-labelledby, aria-describedby, aria-controls, aria-live).

<div class="account-menu">
  <button
    type="button"
    id="menu-button"
    aria-expanded="false"
    aria-controls="menu-list"
  >
    Account
  </button>

  <ul id="menu-list" role="menu" aria-labelledby="menu-button" hidden>
    <li role="none">
      <a role="menuitem" href="/profile">Profile</a>
    </li>
    <li role="none">
      <a role="menuitem" href="/orders">Orders</a>
    </li>
    <li role="none">
      <a role="menuitem" href="/signout">Sign out</a>
    </li>
  </ul>
</div>

The button owns the disclosure state; JavaScript flips aria-expanded in the same handler that toggles the hidden attribute, keeping the visual and announced states in lockstep. role="none" on the list items strips their list semantics so the menu is announced as a flat menu, not a list of lists. Note what is absent: the disclosure behavior here is achievable with the plain button and hidden attributes — roles are only needed if you are truly building a menu widget with arrow-key navigation.

SituationPrefer
Clickable navigationa with href
Action that does not navigatebutton
Show/hide contentbutton + aria-expanded + hidden
Text entryinput with the right type
Announce an update politelyrole="status" or aria-live="polite"
Announce an error immediatelyrole="alert"
Label one control from anotheraria-describedby
Visible label existslabel with for — usually enough alone

Keyboard Navigation and Focus Order

If a feature cannot be operated from the keyboard, it cannot be operated by a large share of assistive-tech users. Native elements handle this automatically: buttons activate on Enter and Space, links on Enter, checkboxes on Space. Custom widgets must reimplement each of those bindings — a tax paid cheerfully by teams that avoided native elements in the first place.

Focus order follows DOM order by default, which is why position: fixed headers and display: contents tricks can scramble tab sequence. tabindex="0" puts an element in the natural order; positive values (tabindex="1" and up) pull it earlier and are almost always a bug. The skip link — the first focusable element on the page — is the cheapest structural win there is:

<a class="skip-link" href="#main-content">Skip to main content</a>

<header class="site-header">
  <nav aria-label="Primary">
    <!-- dozens of links live here -->
  </nav>
</header>

<main id="main-content" tabindex="-1">
  <h1>Order history</h1>
  <!-- page content -->
</main>
.skip-link {
  position: absolute;
  left: -9999px;
}

.skip-link:focus {
  left: 1rem;
  top: 1rem;
  z-index: 100;
  padding: 0.75rem 1rem;
  background: #1e293b;
  color: #fff;
  border-radius: 0.5rem;
}

The link must be visible when focused — hiding it with display: none removes it from the tab order entirely, the classic mistake. The tabindex="-1" on the target lets programmatic focus land cleanly after the jump.

Focus Traps, Modals, and Focus Restoration

Modal dialogs trap focus: Tab cycles inside the dialog, Escape closes it, and focus returns to the element that opened it when it closes. Native dialog with showModal() provides all of that for free. If you build a custom overlay, you must implement the trap yourself — listening for Tab at the last focusable element and cycling to the first, and vice versa — plus the Escape handler and the focus return. In either case, mark the dialog with aria-modal="true" and label it via aria-labelledby pointing at its heading, so screen-reader users know the context they are trapped in.

Live Regions and Status Announcements

Content that appears without a page reload is invisible to screen readers unless announced. Live regions bridge the gap. aria-live="polite" queues an announcement until the user is idle; assertive interrupts. role="status" is shorthand for a polite region, role="alert" for an assertive one — use alerts only for genuine errors, because everything in an alert interrupts.

<p id="save-status" role="status"></p>

<script>
  const statusEl = document.getElementById("save-status");

  function announce(message) {
    // Clearing first guarantees an announcement even for repeated text
    statusEl.textContent = "";
    window.setTimeout(() => {
      statusEl.textContent = message;
    }, 50);
  }

  announce("Draft saved");
</script>

The clear-then-set dance handles the edge case where the same message repeats; assistive tech only fires on a change. Keep announcements short and factual: "Draft saved," not "Your draft has been successfully saved to our servers."

Testing: Keyboard First, Then Tools, Then Humans

Start with the keyboard alone: Tab through the page and confirm the focus indicator is always visible, order makes sense, and every control operates. Then run an automated pass — the axe DevTools extension or Lighthouse catches missing labels, low contrast, and missing alt text in minutes. Automated tools find roughly a third of real issues; the remainder need a screen-reader walkthrough (VoiceOver on macOS, NVDA on Windows) of your core flows. The final check is a session with real users on real assistive tech, because no checklist replaces observed struggle.

Common Mistakes

Replacing native elements and re-implementing their behavior with div plus ARIA

Fix: Follow ARIA's first rule — use button, a, input, and details unless there is truly no native equivalent.

Hiding the skip link with display: none

Fix: Position it off-screen and reveal it on :focus so it stays in the tab order.

Updating the UI without announcing it

Fix: Mirror status changes into a role=status or aria-live region.

Trapping focus in a custom modal without Escape or focus return

Fix: Prefer the native dialog element; otherwise implement trap, Escape, and restoration deliberately.

Relying on automated audits as the whole accessibility strategy

Fix: Automated tools catch roughly a third of issues — pair them with keyboard and screen-reader testing.

Key Takeaways

  • Assistive tech reads an accessibility tree of roles, names, states, and relationships — markup builds that tree.
  • ARIA's first rule: use native HTML for semantics and behavior; add ARIA only for genuine gaps.
  • States must change with the UI — keep aria-expanded and friends in sync in the same handler.
  • Keyboard operability is non-negotiable; skip links, visible focus, and focus traps are the core patterns.
  • Live regions announce dynamic updates — role=status politely, role=alert for real errors.
  • Test with keyboard, automated tools, a screen reader, and ultimately real users.
CW

ChatWhole Learn Editorial Team

Written by experienced data scientists, software engineers, and educators. All content is reviewed by industry professionals to ensure accuracy and relevance.

Last reviewed: 2026-10-12

—
☆☆☆☆☆
0 ratings

Rate & Feedback

Need Expert Web Development Help?

Get personalized tutoring, project support, or professional consulting.

Advertisement