Skip to content
FrontDepth, Home

Accessibility & i18n

ARIA, accessible names and focus management

How browsers expose pages to assistive technology — semantic HTML, the accessibility tree and accessible names, then ARIA roles and states, keyboard patterns like roving tabindex, modal dialogs, live regions and focus management in apps.

JuniorMiddleSeniorUpdated 16 November 2026

Reading level

Shows sections up to the selected level.

Before you start

No prerequisites.

This topic starts at Junior level.

JuniorConcept

Semantic HTML and the accessibility tree

From your markup the browser builds the and, from the DOM, a second tree: the accessibility tree. Screen readers, voice control and switch devices do not look at pixels. They read this tree through the operating system's accessibility API. Each node in it has a role (button, link, heading, checkbox), a name ("Save", "Search"), states and properties (pressed, expanded, checked, disabled) and, for some roles, a value.

Native HTML elements fill all of this in for you:

HTML
<button type="button">Save</button>
<div class="btn" onclick="save()">Save</div>

The <button> is exposed with role button and the name "Save". It is in the tab order, Enter and Space activate it, and the disabled attribute takes it out of the tab order and exposes it as disabled. The <div> is a generic container: no role, not focusable, no keyboard activation. A mouse user sees two identical buttons. A keyboard user cannot reach the second one, and a screen reader reads it as plain text.

What the right element gives you

  • <a href>: a link. It is focusable, Enter follows it, and it shows up in the screen reader's list of links. Without href it is neither a link nor focusable.
  • <button>: an action on the current page, such as "Open menu", "Delete" or "Next slide".
  • <label for> with <input>: a named field. Clicking the label also focuses the field.
  • <h1>–<h6>, <nav>, <main>, <header>, <footer>: headings and landmarks. Screen reader users jump between them instead of listening to the whole page.
  • <ul> / <ol>: announced as "list, 5 items", so users know how much content there is.
  • <dialog>, <details> / <summary>, <select>: complete widgets with keyboard support built in.

A useful rule: a link goes somewhere (the URL changes), a button does something. A "link" that opens a modal and a "button" that navigates both mislead people: they hear one thing and get another.

Looking at the tree

Chrome and Firefox DevTools have an Accessibility panel that shows the computed role, name and states of the selected element, and Chrome can show the full accessibility tree in place of the DOM tree in the Elements panel. When a screen reader says something unexpected, this is the first place to look.

WCAG 2.2 success criterion 4.1.2 Name, Role, Value (level A) requires exactly this information for every user interface component. Native HTML meets it by default; a custom widget has to provide it itself, which is where ARIA comes in.

JuniorConcept

How a control gets its accessible name

The accessible name is what a screen reader says when focus lands on a control ("Search, edit text"), what a voice control user says to activate it ("click Search"), and what appears in the screen reader's lists of links and form fields. The Accessible Name and Description Computation spec (accname) defines where the name comes from. Simplified, the first source that produces non-empty text wins:

  1. aria-labelledby: the text of the referenced elements, in the order of the ids. It works even when the referenced element is hidden.
  2. aria-label: a string on the element itself.
  3. The native label: <label> for form fields, alt for <img>, <caption> for a table, <legend> for a fieldset.
  4. Content: for roles that take their name from content (buttons, links, headings, tabs and others), the text of the descendants, including the alt of images inside.
  5. title, as a last resort. For text inputs, HTML-AAM adds placeholder after title.
HTML
<button type="button" aria-label="Close dialog">
  <svg aria-hidden="true" viewBox="0 0 16 16">…</svg>
</button>

<h2 id="billing-title">Billing address</h2>
<section aria-labelledby="billing-title">…</section>

<label for="email">Email</label>
<input id="email" type="email" autocomplete="email" aria-describedby="email-hint">
<p id="email-hint">We send the receipt here.</p>

<a href="/cart"><img src="/icons/cart.svg" alt="Cart"></a>

aria-describedby adds a description, which is read after the name and role. It is the right place for hints and error messages; the name stays short.

Common mistakes

  • Icon-only buttons without a name. <button><svg>…</svg></button> is announced as just "button". Give the button aria-label (or visually hidden text) and mark the decorative icon aria-hidden="true".
  • Placeholder as the label. It disappears as soon as the user types, usually has low contrast, and is only the last fallback in the name computation. Keep a visible <label>; use the placeholder for an example format at most.
  • A name that contradicts the visible text. WCAG 2.5.3 Label in Name (level A): if a control shows a text label, its accessible name must contain that text, ideally at the start. A "Buy" button named "Add product to basket" fails for voice control: the user says "click Buy" and nothing happens.
  • aria-label on a plain <div> or <span>. WAI-ARIA 1.2 prohibits naming the generic role (and others such as paragraph), so screen readers may ignore it. Names belong on interactive elements, landmarks, images and similar roles.
  • Ten links called "Read more". In the list of links they are indistinguishable. Put the item name into the link text, visibly or as visually hidden text.

The Signup form and Product grid challenges on this platform are largely about names: axe reports some of the problems, and the rest only show up when you tab through the page and check what each control is actually called.

JuniorWeb platform

Keyboard access, tab order and visible focus

Many people never use a mouse: keyboard-only users, screen reader users, and people with switch devices or voice control, which drive the keyboard interface indirectly. WCAG 2.1.1 Keyboard (level A) requires that all functionality works from a keyboard, and 2.1.2 No Keyboard Trap (level A) that focus can always be moved away from a component.

The expected keys:

  • Tab / Shift+Tab move between interactive elements.
  • Enter follows links and activates buttons; Space activates buttons and toggles checkboxes.
  • Arrow keys move inside composite widgets: radio groups, tabs, menus, listboxes.
  • Escape closes dialogs, menus and popups.

Tab order and tabindex

The sequential focus order is the DOM order of focusable elements. tabindex changes focusability:

HTML
<div role="button" tabindex="0">In the tab order, at its DOM position</div>
<h1 tabindex="-1">Focusable from script only</h1>
<input tabindex="3">
  • tabindex="0" puts an element into the tab order at its DOM position. Use it for a custom widget that also has a role and key handling. Making plain text focusable only adds useless stops.
  • tabindex="-1" makes an element focusable with element.focus() but skipped by Tab. Use it for focus targets (the heading of a new view, an error summary) and for the inactive items of a roving tabindex.
  • Positive values (1 and up) are visited before everything else, in numeric order. The APG strongly advises against them: one positive value reorders the whole page and breaks as soon as the markup changes. WCAG 2.4.3 Focus Order (level A) asks for an order that preserves meaning, so fix the order by fixing the DOM.

CSS that reorders boxes (order, flex-direction: row-reverse, grid placement) changes only the visual order; focus still follows the DOM. If the two differ, keyboard users see focus jump around.

A native disabled control leaves the tab order. aria-disabled="true" keeps it focusable, so users can still discover it and read why it is unavailable, but then you must block activation yourself.

Visible focus

WCAG 2.4.7 Focus Visible (level AA): keyboard users must see where focus is. The classic bug is *:focus { outline: none; } in a reset stylesheet. Style :focus-visible instead (Baseline widely available since March 2022). The browser matches it for keyboard focus (and in most cases for focus moved by script), but usually not after a mouse click on a button:

CSS
:focus-visible {
  outline: 3px solid var(--focus-ring);
  outline-offset: 2px;
}

WCAG 2.2 added 2.4.11 Focus Not Obscured (Minimum) (level AA): the focused element must not be completely hidden by your own content, such as a sticky header or a cookie banner. scroll-padding-top set to the header height keeps elements scrolled into view below it.

MiddleConcept

ARIA: roles, states, properties and the rules of use

WAI-ARIA is a set of attributes that changes only what the accessibility tree reports. role sets the role. aria-* attributes set states, which change during use (aria-expanded, aria-selected, aria-checked, aria-pressed, aria-invalid, aria-current), and properties, which describe relationships and rarely change (aria-controls, aria-labelledby, aria-describedby, aria-haspopup).

ARIA adds no behaviour. role="button" does not make a <div> focusable, does not turn Enter into a click and does not change how it looks. The APG puts it as "a role is a promise": you promise the user the keyboard behaviour of that role and then have to write it.

HTML
<div role="button" tabindex="0" aria-pressed="false">Bold</div>

<button type="button" aria-pressed="false">Bold</button>

The div still needs a keydown handler for Enter and Space, a disabled state and focus styles. The button already has all of it; it only needed aria-pressed to become a toggle button.

The rules of ARIA use

The W3C note Using ARIA lists four rules:

  1. If you can use a native HTML element with the semantics and behaviour you need, do so. This is the "first rule of ARIA".
  2. Do not change native semantics unless you really have to. <h2 role="tab"> stops being a heading. Put a <button> inside the heading, or the role on a wrapper.
  3. All interactive ARIA controls must be usable with the keyboard. Adding role="slider" means implementing the arrow keys too.
  4. Do not use role="presentation" or aria-hidden="true" on a focusable element. Keyboard users would land on something that does not exist for their screen reader.

The APG makes the same point under the heading "No ARIA is better than bad ARIA": incorrect ARIA misrepresents the interface to the people who rely on it, which is worse than no ARIA at all.

States must follow the UI

ARIA states are a contract with the user. When the interface changes, the attribute changes with it: aria-expanded on a menu button while the menu is open, aria-selected="true" on exactly one tab, aria-current="page" on the navigation link of the current page. A common bug is an attribute written once in the markup and never updated, so the screen reader says "collapsed" for an open menu. In React, derive the attribute from the same state that drives the UI:

JSX
function FiltersToggle({ open, onToggle }) {
  return (
    <button
      type="button"
      aria-expanded={open}
      aria-controls="filters"
      onClick={onToggle}
    >
      Filters
    </button>
  );
}

React renders the boolean as the string "true" or "false", which is exactly what ARIA expects.

Also check that the attribute exists for the role: aria-checked belongs to checkboxes, radios and switches, and aria-selected to tabs, options and grid cells. axe and the Accessibility panel both report attributes that a role does not support.

MiddleExample

Composite widgets: tabs and the roving tabindex

Widgets made of many items (tabs, radio groups, menus, listboxes, toolbars, grids) are composite widgets. Tab moves into the widget once and out of it once; the arrow keys move between the items inside. A tablist with eight tabs costs one Tab stop, not eight.

The APG Tabs pattern:

  • The container has role="tablist" and a name; each tab has role="tab", aria-selected and aria-controls; each panel has role="tabpanel" and aria-labelledby pointing at its tab.
  • Tab moves focus to the active tab; the next Tab goes to the panel. A panel without focusable content gets tabindex="0" so its text can be reached.
  • Left / Right Arrow move to the previous / next tab and wrap around at the ends; Home and End (optional) jump to the first and last tab.
  • Automatic activation (the panel changes as focus moves) is recommended when panels appear without noticeable delay. If a panel has to load first, use manual activation: arrows move focus, Enter or Space selects.

Roving tabindex

Exactly one tab has tabindex="0": the selected one. All others have tabindex="-1". The arrow keys move the 0 and call focus() on the new tab:

JSX
function Tabs({ tabs }) {
  const [active, setActive] = useState(0);
  const refs = useRef([]);

  function onKeyDown(event) {
    const last = tabs.length - 1;
    const next = {
      ArrowRight: active === last ? 0 : active + 1,
      ArrowLeft: active === 0 ? last : active - 1,
      Home: 0,
      End: last,
    }[event.key];
    if (next === undefined) return;
    event.preventDefault();
    setActive(next);
    refs.current[next].focus();
  }

  return (
    <>
      <div role="tablist" aria-label="Account settings" onKeyDown={onKeyDown}>
        {tabs.map((tab, i) => (
          <button
            key={tab.id}
            ref={(el) => {
              refs.current[i] = el;
            }}
            type="button"
            role="tab"
            id={`tab-${tab.id}`}
            aria-selected={i === active}
            aria-controls={`panel-${tab.id}`}
            tabIndex={i === active ? 0 : -1}
            onClick={() => setActive(i)}
          >
            {tab.label}
          </button>
        ))}
      </div>
      {tabs.map((tab, i) => (
        <div
          key={tab.id}
          role="tabpanel"
          id={`panel-${tab.id}`}
          aria-labelledby={`tab-${tab.id}`}
          tabIndex={0}
          hidden={i !== active}
        >
          {tab.content}
        </div>
      ))}
    </>
  );
}

This is automatic activation: moving focus also selects. Because the selected tab is the only one with tabIndex={0}, Tab from outside always lands on it.

aria-activedescendant

The alternative keeps DOM focus on the container and sets aria-activedescendant to the id of the "active" item; assistive technology treats that item as focused. You draw the highlight yourself and scroll the item into view. It is the usual choice for a combobox, where focus must stay in the text input while the arrows move through the options. When the items can take focus themselves, roving tabindex is simpler.

Hiding the inactive panels

Inactive panels must be gone for everyone, not just invisible: hidden, not rendering them at all, or inert on top of a visual hiding (for an animated transition). Panels hidden only with opacity: 0 or aria-hidden keep their links and buttons in the tab order.

The Tabs challenge gives you a half-finished tabs widget to repair.

SeniorWeb platform

Hiding content and announcing changes

"Hidden" means three different things, and mixing them up causes many bugs:

TechniqueVisibleIn the accessibility treeFocusable
hidden, display: none, visibility: hiddennonono
aria-hidden="true"yesnoyes
visually hidden CSSnoyesyes
opacity: 0, zero height, moved off-screennoyesyes
inertyesnono
  • hidden / display: none remove content for everyone: closed menus, inactive tab panels. A trap: hidden works through the browser's own display: none, and any author rule such as .panel { display: grid; } overrides it, so the "hidden" panel shows up again. Add [hidden] { display: none !important; } to your base styles.
  • aria-hidden="true" hides content from assistive technology only: decorative icons next to text, a visual duplicate of something already announced. Never on a focusable element or on a container of one (the fourth rule of ARIA).
  • Visually hidden text is for screen readers only, such as "Read more about the Trail backpack" or a skip link that appears on focus:
CSS
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

Live regions

When content changes and focus does not move (a "Saved" toast, the number of search results, an error after async validation), a screen reader says nothing. It announces the change only if it happens inside a live region:

HTML
<div id="cart-status" role="status" class="visually-hidden"></div>
JavaScript
async function addToCart(product) {
  await api.addToCart(product.id);
  document.getElementById("cart-status").textContent = `${product.name} added to cart`;
}
  • role="status" has an implicit aria-live="polite" and aria-atomic="true": the message is read when the user is idle. Use it for most messages. WCAG 4.1.3 Status Messages (level AA) requires status messages to be exposed through a role or property, so assistive technology can present them without moving focus.
  • role="alert" is assertive (aria-live="assertive", aria-atomic="true") and interrupts whatever is being read. Keep it for urgent, time-sensitive errors.
  • The region must exist before the change. Screen readers announce changes to a region they already know about. Render it once, empty (in the layout, for example), and then change its text. Inserting <div role="status">Saved</div> in one step is often missed; MDN notes that role="alert" is the exception and is announced even when injected.
  • Announce less. One short message per event, no announcement per keystroke ( a live result count), and no live region around content that changes all the time, such as a ticking clock.
SeniorPitfalls

Focus in dynamic apps, and what automated checks miss

In a single-page app the DOM changes under the user. When the focused element is removed, document.activeElement becomes <body>: the next Tab starts again from the top of the page, and a screen reader may say nothing at all. Every place where your UI removes or replaces the focused element needs a decision.

  • Deleting the focused item. Move focus to the next item, to the previous one if it was the last, or to the list's heading when the list is now empty.
  • Route changes. The new view appears without a page load, so nothing is announced. Focus its <h1> (with tabindex="-1"), update document.title, or announce the page in a live region. Next.js has a built-in route announcer that reads document.title, then the <h1>, then the pathname. The Client-side routing topic covers this in detail.
  • Closing popovers, menus and inline editors. Return focus to the trigger: after "Save", focus the "Edit" button that is shown again.
  • "Load more" and infinite lists. Move focus to the first new item, or keep it on the button and announce how many items were added.
  • Form errors. After a failed submit, focus the first invalid field or an error summary that links to the fields; tie each message to its field with aria-describedby and set aria-invalid="true".
JavaScript
function removeTodo(button) {
  const buttons = [...list.querySelectorAll("button.remove")];
  const i = buttons.indexOf(button);
  const next = buttons[i + 1] ?? buttons[i - 1];
  button.closest("li").remove();
  (next ?? listHeading).focus();
}

listHeading has tabindex="-1", so it can take focus from script without becoming a Tab stop. In React, run the same logic after the state update, for example by storing the id to focus and calling focus() in an effect once the list has re-rendered.

What automated checks find, and what they miss

axe-core, which also powers Lighthouse's accessibility audit, checks rules over the DOM: missing names, ARIA attributes a role does not support, contrast, duplicate ids, missing labels. Deque, the company behind it, says it finds on average 57% of WCAG issues automatically, and it marks some results as "incomplete" for manual review. It cannot judge whether:

  • the focus order makes sense, and focus returns after a dialog closes;
  • arrow keys work in a widget, and Escape closes it;
  • a name is meaningful, not just present ("button 1", "image");
  • a live message is announced at the right moment, once.

That is why the A11y Hunt challenges mix axe issues with manual ones that only a keyboard walk-through reveals. A practical routine: lint (eslint-plugin-jsx-a11y) and axe in component and end-to-end tests to catch regressions, then for every critical flow a keyboard pass (Tab through all of it, open and close every widget, never touch the mouse), a look at names in the Accessibility panel, and a run with a screen reader such as VoiceOver or NVDA.

SeniorInterview tips

Interview tips

A 30-second answer. "Assistive technology reads the accessibility tree: role, name, state. Semantic HTML fills it in and brings keyboard support for free, so I start there. ARIA only changes what the tree reports and adds no behaviour, so I use it to fill gaps in custom widgets and keep its states in sync with the UI. Then I manage focus: always visible, in a logical order, and moved deliberately when content opens, closes or disappears."

Questions you are likely to get

  • Make this clickable div accessible. Best answer: replace it with a <button>. If you really cannot, list everything that is then your job: role, tabindex="0", Enter and Space, the disabled state, focus styles.
  • How does a screen reader know what this button is called? The name computation: aria-labelledby, aria-label, the native label or alt, the content, title. Mention 2.5.3 Label in Name.
  • Build an accessible modal. <dialog> with showModal(), or by hand: role, aria-modal, a name, inert on the page, Escape, focus in and back. Explain your choice of initial focus.
  • Keyboard support for tabs or a menu. One Tab stop, arrows inside, roving tabindex or aria-activedescendant, automatic vs manual activation.
  • aria-hidden vs display: none vs visually hidden. Who each one hides content from, and why aria-hidden on focusable content is a bug.
  • How do you announce "Saved"? A live region that already exists, role="status", text changed afterwards.
  • How do you test accessibility? Automated checks plus a keyboard pass, the Accessibility panel and a screen reader; automation finds only part of the issues.

Mistakes that cost points

  • "Add ARIA to make it accessible." ARIA without behaviour is a broken promise, and bad ARIA is worse than none.
  • outline: none without a replacement focus style.
  • Positive tabindex to "fix" the order instead of fixing the DOM.
  • aria-label everywhere: on generic divs, or replacing visible text with different words.
  • Treating a Lighthouse score of 100 as "accessible".

Senior signal

Talk about systems, not single fixes: accessible primitives in the design system (dialog, tabs, menu, combobox) so product teams do not rebuild them; lint and axe in CI plus keyboard tests for critical flows; one focus policy for route changes across the app. Name the target, usually WCAG 2.2 level AA, and the legal context where it applies, such as the European Accessibility Act, which has applied since 28 June 2025.

JuniorReview checklist

What to check when reviewing ARIA and focus management

Use this list on UI code you did not write: a teammate's pull request, a library component or an AI assistant's suggestion. A page that works with a mouse can still be unreachable by keyboard or silent for a screen reader, and axe catches only part of it.

  • Is every clickable element native: <button> for actions, <a href> for navigation? A <div onclick> gets no Tab stop, no Enter or Space and no role. Put the mouse aside and Tab through the change.
  • Does every control have a meaningful name that contains its visible text? Read the computed name in the DevTools Accessibility panel; a bare "button", or a name unlike the label on screen, fails screen reader and voice control users.
  • Does every role come with that role's behaviour? ARIA only changes what the accessibility tree reports: role="button" on a div still needs tabindex="0", Enter and Space.
  • Is focus always visible? Look for outline: none with no replacement; style :focus-visible instead, and check that a sticky header never hides the focused element.
  • When something opens, closes or is removed, where does focus go? Removing the focused element leaves document.activeElement on <body>, so the next Tab starts from the top. Log document.activeElement after each action; a closed menu should return focus to its trigger.
  • Do ARIA states follow the UI? aria-expanded, aria-selected and aria-pressed must come from the state that drives the UI. Toggle the control and watch the Accessibility panel.
  • Does the Tab order match the visual order, with no stops on invisible content? Positive tabindex reorders the whole page, CSS order moves only the boxes while focus follows the , and content hidden with opacity: 0 or aria-hidden stays focusable.

Check your understanding

  • Practice

    Predict-output and open interview questions with self-assessment.

    3 predict-output · 3 open

  • Quiz

    Multiple-choice questions with explanations and a score.

    6 questions

Hands-on work that uses this topic.