Accessibility Foundations — Semantics, Accessible Names, and useId
Accessibility is part of component correctness. React produces DOM; the browser exposes that DOM through semantics, names, states, relationships, focus, and the accessibility tree.
Native HTML first
Prefer:
<button onClick={save}>Save</button>
over:
<div role="button" tabIndex={0} onClick={save}>
Save
</div>
The native button already owns button semantics, focusability, keyboard activation, disabled behavior, and mature browser/assistive-technology support.
A role changes semantics. It does not automatically implement keyboard behavior.
Choose elements by meaning
<nav aria-label="Primary">...</nav>
<main>...</main>
<article>...</article>
<button>Delete</button>
<a href="/settings">Settings</a>
A control that navigates is usually a link. A control that performs an action is usually a button.
Accessible names
Interactive elements need a useful name.
<button>Save profile</button>
For an icon-only control:
<button aria-label="Close dialog">
<CloseIcon aria-hidden="true" />
</button>
Visible text is often easiest for everyone to perceive and maintain.
Forms need persistent labels
<label htmlFor={emailId}>Email address</label>
<input id={emailId} type="email" />
A placeholder is not a durable replacement for a label because it disappears during input and provides weaker orientation.
Names and descriptions are different
const inputId = useId();
const hintId = `${inputId}-hint`;
return (
<>
<label htmlFor={inputId}>Password</label>
<input id={inputId} type="password" aria-describedby={hintId} />
<p id={hintId}>Use at least 12 characters.</p>
</>
);
useId creates stable DOM relationships
function EmailField() {
const id = useId();
return (
<>
<label htmlFor={id}>Email</label>
<input id={id} type="email" />
</>
);
}
One base ID can create several relationships:
const baseId = useId();
const inputId = `${baseId}-input`;
const hintId = `${baseId}-hint`;
const errorId = `${baseId}-error`;
key, DOM id, and domain identity are different
Do not use useId for list keys, persisted record IDs, analytics entity IDs, API resource IDs, or cache keys.
Keys come from the data:
items.map(item => <Row key={item.id} item={item} />)
React's current documentation also notes that useId cannot currently be called in async Server Components.
Landmarks and headings communicate structure
<header>...</header>
<nav aria-label="Primary">...</nav>
<main>...</main>
<aside>...</aside>
<footer>...</footer>
When multiple landmarks share a type, give them distinguishable names where useful.
<nav aria-label="Primary">...</nav>
<nav aria-label="Account">...</nav>
Headings describe document structure, not visual size:
<h1>Account settings</h1>
<h2>Profile</h2>
<h2>Security</h2>
<h3>Two-factor authentication</h3>
Images and icons
Informative image:
<img src={chartUrl} alt="Revenue increased 18% from January to June" />
Decorative image:
<img src={dividerUrl} alt="" />
A decorative icon inside an already-named button should usually stay out of the accessibility name:
<button>
<SaveIcon aria-hidden="true" />
Save
</button>
ARIA states must match real UI state
<button
aria-expanded={open}
aria-controls={panelId}
onClick={() => setOpen(value => !value)}
>
Filters
</button>
If ARIA says one thing while the visible UI does another, the accessibility tree is lying.
Validation relationships
function EmailField({ error }: { error?: string }) {
const id = useId();
const errorId = `${id}-error`;
return (
<div>
<label htmlFor={id}>Email</label>
<input
id={id}
type="email"
aria-invalid={error ? true : undefined}
aria-describedby={error ? errorId : undefined}
/>
{error && <p id={errorId}>{error}</p>}
</div>
);
}
aria-invalid communicates state; aria-describedby connects the explanation. Add live-region behavior only when the product genuinely needs an announcement.
Native disabled vs aria-disabled
Prefer native disabled controls when they match the design.
Hidden is not one concept
A subtree may be visually hidden, removed from layout, not focusable, absent from the accessibility tree, or React-hidden with state preserved. These are not equivalent.
Be especially careful with aria-hidden="true": descendants disappear from assistive technology. Do not leave meaningful focusable controls inside such a subtree without a deliberate, tested pattern.
Semantic testing reinforces accessibility
screen.getByRole('button', { name: 'Save profile' });
screen.getByLabelText('Email address');
screen.getByRole('navigation', { name: 'Primary' });
These tests protect important parts of the accessibility surface, but they are not a complete accessibility audit.
Review checklist
- Is there a native element with the correct meaning?
- Does every interactive control have a useful accessible name?
- Are form controls visibly labeled?
- Are hints/errors connected through correct relationships?
- Do ARIA states match actual UI state?
- Are generated IDs unique and used only for DOM relationships?
- Are icons/images classified by purpose?
- Do landmarks/headings make page structure understandable?
- Can semantic tests find the important UI?
- Have you avoided ARIA where native HTML already solves the problem?
Interview questions
- Why should semantic HTML come before ARIA?
- What is an accessible name?
- When would you use
aria-labelledbyinstead ofaria-label? - What problem does
useIdsolve? - Why should
useIdnot generate list keys? - What is the difference between
disabledandaria-disabled?