Lesson 6 of 12 · 11 min · Accessibility

Accessibility: semantic markup and ARIA

Covers: WCAG 2.2 and the WAI-ARIA Authoring Practices. Updated 13 Nov 2026. Part of the Frontend Developer roadmap.

What you will learn

  • Why accessibility matters and what WCAG asks for
  • How browsers expose pages to assistive technology
  • Use semantic HTML first
  • The rules of ARIA, and aria-label, aria-labelledby, aria-describedby, aria-expanded, aria-live
  • Build a disclosure and a dialog correctly

In simple words

Not everyone uses a website the same way. Some people cannot see the screen and use a program that reads it aloud. Some cannot use a mouse and move with the keyboard. Some have low vision, colour blindness, tremor, or are on a bright street with a cracked phone. Accessibility means building pages that work for all of them. The surprising part is that most of it comes free if you use the right HTML.

Words to know

  • Assistive technology: software and devices that help disabled people use computers, such as screen readers.
  • Screen reader: software that reads page content aloud or to a braille display.
  • Accessibility tree: the simplified version of the page that the browser gives to assistive technology.
  • ARIA: attributes that add accessibility information to elements when HTML alone is not enough.

Why it matters

  • People: about one in six people worldwide lives with a significant disability; many more have temporary or situational limits (a broken arm, glare, noise, a slow connection). In India, a very large number of users are on phones and may use larger text or voice tools.
  • Law and policy: many countries require accessible websites; in India, the Rights of Persons with Disabilities Act, 2016 covers accessibility of information and communication technology, and government sites follow the GIGW guidelines. Procurement and clients increasingly ask for it.
  • Business: accessible sites reach more customers, rank better, and are usually cleaner and faster. The same techniques help everyone (captions, keyboard shortcuts, clear forms).
  • Quality: it is a mark of professional front-end work and a frequent interview topic.

WCAG in plain words

The Web Content Accessibility Guidelines (WCAG), from the W3C, are the international standard. The current version is WCAG 2.2. It is built on four principles, POUR:

Principle Meaning Example
Perceivable people can perceive the content text alternatives for images, captions for video, enough contrast
Operable people can operate the interface everything works by keyboard, no keyboard traps, enough time, no flashing
Understandable content and controls are understandable clear language, predictable behaviour, helpful error messages
Robust works with current and future technology, including assistive technology valid HTML, correct names, roles and states

There are conformance levels A, AA and AAA. Level AA is the usual target (and the one laws and contracts usually require). Automated tools find only about a third of issues, so manual testing with a keyboard and a screen reader is essential.

The accessibility tree

The browser builds an accessibility tree from the DOM: for each element, a role (button, link, heading, checkbox), a name (the label that is announced), a description, and states (checked, expanded, disabled, required). Assistive technology reads this tree, not the pixels. A <button>Save</button> becomes "Save, button". A <div class="btn" onclick="save()">Save</div> is, to a screen reader, just text: no role, not focusable, no keyboard support. You can inspect the tree in browser DevTools (the Accessibility panel).

First rule: use semantic HTML

The best ARIA is no ARIA. Native elements already have the right role, name, states and keyboard behaviour built in:

Instead of Use
<div onclick> <button type="button">
<span class="link"> <a href="...">
<div class="header"> <header>, <nav>, <main>, <footer>
<div class="title"> <h1>...<h6>
a list built from <div>s <ul>/<ol> and <li>
<div class="checkbox"> <input type="checkbox"> with a <label>
a modal made of <div>s <dialog>
an accordion made of <div>s <details> and <summary>

Semantic HTML also gives you form labels, table headers (<th scope>), <fieldset>/<legend>, lang for pronunciation, and alt for images (the semantic HTML and forms lessons).

ARIA: the rules

WAI-ARIA adds attributes that describe roles, names and states when HTML has no suitable element, typically for custom widgets (tabs, comboboxes, menus, tree views). The first rule of ARIA, from the specification, is: if you can use a native HTML element or attribute with the semantics you need, do that instead of ARIA. The other rules:

  1. Do not change native semantics unless you really must (<h2 role="tab"> is a smell).
  2. All interactive ARIA controls must be usable by keyboard and focusable.
  3. Do not hide a focusable element with aria-hidden="true" or role="presentation".
  4. All interactive elements must have an accessible name.

Bad ARIA is worse than no ARIA: a wrong role or a missing keyboard handler gives screen reader users false promises. ARIA changes only what is announced; it adds no behaviour: you must provide the keyboard handling and focus management yourself.

Names and descriptions

Every control needs an accessible name. In order of preference:

<button>Save</button>                                         <!-- visible text: best -->
<label for="q">Search</label><input id="q" type="search">     <!-- a label -->
<button aria-label="Close dialog"><svg aria-hidden="true">...</svg></button>   <!-- icon-only button -->
<section aria-labelledby="h-orders"><h2 id="h-orders">Your orders</h2>...</section>
<input id="pw" type="password" aria-describedby="pw-hint">
<p id="pw-hint">At least 12 characters.</p>
  • aria-label gives an invisible name; aria-labelledby points to the id of visible text that names the element (preferred, because it is visible and translatable); aria-describedby adds a longer description or an error message.
  • The accessible name should start with the visible text (so voice-control users can say what they see).
  • Decorative icons get aria-hidden="true"; informative images get alt.
  • Several <nav> elements need distinct names: aria-label="Main", aria-label="Footer".

States and properties

ARIA states update as the interface changes (JavaScript must change them):

Attribute Use
aria-expanded="true|false" a button that opens or closes something (menu, accordion)
aria-controls which element it controls (support varies; useful as documentation)
aria-current="page" the current link in navigation (or step, date)
aria-pressed a toggle button
aria-selected, aria-checked tabs, options, custom checkboxes
aria-disabled="true" disabled but still focusable (for explaining why)
aria-invalid="true" a field with an error
aria-required="true" a required custom control (native required is better)
aria-hidden="true" removes decorative content from the accessibility tree
aria-busy a region being updated

Live regions: announcing changes

Dynamic updates (a toast "Saved", a form error summary, a search result count) are silent to screen reader users unless announced. A live region is announced when its content changes:

<div role="status" aria-live="polite" id="status"></div>      <!-- polite: waits for a pause -->
<div role="alert">Your session will expire in 1 minute.</div>  <!-- assertive: interrupts; use rarely -->
document.getElementById("status").textContent = "12 results found";

The live region must exist in the page before you change its text. Use polite almost always, and alert only for urgent errors.

Example: a disclosure (show and hide)

<button aria-expanded="false" aria-controls="faq-1" id="btn-1">What is included in the free plan?</button>
<div id="faq-1" hidden>One short interview and one resume review.</div>
const btn = document.getElementById("btn-1");
const panel = document.getElementById("faq-1");
btn.addEventListener("click", () => {
  const open = btn.getAttribute("aria-expanded") === "true";
  btn.setAttribute("aria-expanded", String(!open));
  panel.hidden = open;
});

Even simpler: <details><summary>What is included?</summary>...</details> does all of this natively.

Example: a modal dialog

Use the native <dialog> and showModal(): it traps focus inside, closes on Escape, makes the rest of the page inert, and returns focus when closed:

<dialog id="confirm" aria-labelledby="confirm-title">
  <h2 id="confirm-title">Delete this resume?</h2>
  <p>This cannot be undone.</p>
  <form method="dialog">
    <button value="cancel">Cancel</button>
    <button value="ok">Delete</button>
  </form>
</dialog>

If you build a custom dialog you must do all of that yourself (role, label, focus trap, Escape, return focus), which is why the native element is preferred. For complex widgets (tabs, menus, comboboxes) follow the ARIA Authoring Practices Guide (APG) patterns for roles and keyboard interaction, or use a well-tested accessible component library (Radix UI, React Aria, Headless UI) instead of writing your own.

Testing

  • Automated tools: the browser's Lighthouse, the axe DevTools extension, and linters (eslint-plugin-jsx-a11y for React). They catch missing alt text, labels and contrast, but only part of the problems.
  • Keyboard: unplug the mouse and use the whole page (next lesson).
  • Screen reader: NVDA (free, Windows), VoiceOver (macOS and iOS), TalkBack (Android), JAWS. Check headings, landmarks, forms and dynamic updates.
  • Zoom and text size: 200 percent and larger default fonts.
  • Real users with disabilities give feedback no tool can.

Common mistakes

  • <div> and <span> for buttons and links.
  • ARIA on top of broken HTML, or ARIA without keyboard support.
  • Icon-only buttons with no name.
  • Forgetting to update aria-expanded and other states.
  • Placeholders as labels.
  • Dynamic content updates that screen readers never hear.
  • Relying only on automated checks.

Try it yourself

  1. Replace three clickable <div>s with <button> and <a> and notice the keyboard and screen reader difference.
  2. Inspect a page's accessibility tree in DevTools and check the names of its buttons and links.
  3. Add aria-expanded handling to a hand-built menu button, then replace it with <details>.
  4. Add a role="status" region that announces "3 results" after a search.
  5. Turn on a screen reader (NVDA or TalkBack) and listen to your page's headings and form.

Check yourself

What is the first rule of ARIA?

If a native HTML element or attribute provides the semantics you need, use it instead of ARIA.

What is the difference between aria-label and aria-labelledby?

aria-label supplies the name as a string; aria-labelledby points to the id of visible text that names the element.

Does adding role="button" to a <div> make it work by keyboard?

No. ARIA changes only what is announced; you must add focusability and Enter and Space handling yourself, which is why <button> is better.

How do you make a screen reader announce a status message?

Put the text in a live region (role="status" or aria-live="polite") that already exists in the page.

Interview questions

What is web accessibility and how do you build for it?

Making sites usable by people with disabilities. Use semantic HTML, labels and alt text, sufficient colour contrast, full keyboard support with visible focus, ARIA only where needed, accessible forms and errors, and test with automated tools, a keyboard and screen readers against WCAG 2.2 AA.

What are the four principles of WCAG?

Perceivable, Operable, Understandable and Robust (POUR).

When is ARIA appropriate?

For custom widgets with no native HTML equivalent, such as tabs, comboboxes and live regions, always combined with the right keyboard behaviour and focus management.

Summary

  • Accessibility serves many people and is required by law and good practice; target WCAG 2.2 AA.
  • Browsers expose an accessibility tree of roles, names and states; semantic HTML provides these for free.
  • Use ARIA only when HTML falls short, follow its rules, and add the keyboard behaviour yourself.
  • Name every control, announce dynamic changes with live regions, prefer native <dialog> and <details>, and test with real tools.

Going deeper

See how much of this you can explain

A free mock interview asks you new questions on HTML, CSS and how the web works for Frontend Developer and scores every answer, with what to fix.