Search topics
Invalid ARIA that misleads screen readers
A gift-wrap checkbox points aria-labelledby at a renamed label id, or writes its role as aria-role, so a screen reader hears a nameless box or no checkbox.
aria-labelledby="gift-wrap-label" … id="giftwrap-label" The problem
Screen reader users can't tell what the gift-wrap box is for, or that it can be ticked at all
A shop's checkout has one extra option above the Place order button: a small square box and the words "Gift wrap this order". It isn't a real checkbox. It is a div drawn as a box, with a script that draws a tick when it is clicked or when Space is pressed on it, and ARIA to tell assistive technology what it is. The ARIA has one wrong word in it. In one version of the page, the box takes its name from the words beside it with aria-labelledby="gift-wrap-label", but the words' id is giftwrap-label: it was renamed in the template, and the reference was left as it was. A screen reader user tabs to the box and hears only "checkbox, not checked". The tick works, and its state is read correctly, but nothing says what the box is for, so they guess from what came before it, or leave it alone. In another version, the role is written as aria-role="checkbox". The screen reader says only "Gift wrap this order", with no role and no state, and nothing at all when Space is pressed.
ARIA is a fixed vocabulary, and its references have to point at something. Each role, each attribute and each value an attribute can take is listed in the specification, an id reference has to name an element on the page, and a browser builds the accessibility tree only from the words it knows and the references it can follow. Anything else is an author error, which browsers handle by set rules, not by guessing what the author meant:* (source 2)
aria-labelledbynames an element by its id. When no element on the page has that id, the reference is skipped, as if the attribute weren't there, and the browser looks for the name elsewhere: inaria-label, then, for a checkbox, in the text inside it.* (source 5) The words "Gift wrap this order" sit beside the box, not inside it, so there is nothing to fall back on, and the checkbox has no name.aria-roleis not an attribute at all. The browser ignores it, so thedivkeeps its own role,generic, which has no state. The correctaria-checkedbeside it is ignored too, because a generic element can't be checked.- A
rolewith no role ARIA defines, such asrole="check-box", is treated as if no role had been given, with the same result.* (source 2)
Each version fails 4.1.2 Name, Role, Value: the name, or the role and state, that a control must expose to assistive technology is missing, even though the source looks as though it sets them all.
The first version passes a look at the markup: aria-labelledby is spelt right, and the label is on screen beside the box. Only the browser's accessibility tree, or a screen reader, shows that the name is empty. The same slip happens whenever an option is copied or its id renamed in one place only, so one checkout can have one option named and the next one not.
3 of 10 groups affected
- No vision (affected)
- Low vision (affected)
- Colour vision (not affected)
- No hearing (not affected)
- Hard of hearing (not affected)
- No speech (not affected)
- Motor (affected)
- Reach, strength (not affected)
- Cognitive (not affected)
- Seizures (not affected)
- Without vision Screen reader and braille display users hear "checkbox, not checked" with no name, or only the words "Gift wrap this order" with no sign that they can be ticked, so they leave the wrong choice in their order or never find the option.
- Limited manipulation Voice control users who say "Click Gift wrap this order" have nothing by that name to click while the box has no name, and fall back on showing numbers or a grid.
- Limited vision People who use a magnifier with speech see the words beside the box but hear only "checkbox", and have to guess that the two belong together.
axe checks every ARIA word against the specification, so it reports aria-role (aria-valid-attr) and role="check-box" (aria-roles) reliably. An id that isn't there is handled differently: axe doesn't report an aria-labelledby that points at nothing, but sends it for review under aria-valid-attr-value. What it does report is the result, a checkbox with no name (aria-toggle-field-name), which says nothing about the reference behind it. It checks the page only in the state it finds it in, too: a script that redraws the option after the first click, with new ids or a new role, passes a scan of the page as it loads. A scanner also can't tell whether a valid role is the right one, or whether the name it finds is the label shown beside the box. A quick fix can make things worse. Deleting the attribute axe names silences the report and leaves a box with no role or no name. Copying the label's words into aria-label gives the box a name today, but the words then live in two places, and the next edit to the label changes only one of them. Adding aria-checked to a native checkbox "to be safe" adds an attribute browsers ignore there, and axe reports it under aria-conditional-attr as soon as it disagrees with the real state.
What the checkers report
- axe DevTools
- Elements must only use supported ARIA attributes
- ARIA role should be appropriate for the element
- aria-braille attributes must have a non-braille equivalent
- ARIA attributes must be used as specified for the element's role
- Deprecated ARIA roles must not be used
- ARIA roles used must conform to valid values
- "role=text" should have no focusable descendants
- ARIA toggle fields must have an accessible name
- ARIA tooltip nodes must have an accessible name
- ARIA attributes must conform to valid values
- ARIA attributes must conform to valid names
- Elements marked as presentational should be consistently ignored
- Lighthouse
[aria-*]attributes do not match their roles- Uses ARIA roles on incompatible elements
- ARIA attributes are not used as specified for the element's role
- Deprecated ARIA roles were used
[role]values are not valid- Elements with the
role=textattribute do have focusable descendents. - ARIA toggle fields do not have accessible names
- ARIA
tooltipelements do not have accessible names. [aria-*]attributes do not have valid values[aria-*]attributes are not valid or misspelled- Elements with
role="none"orrole="presentation"have conflicts
- WAVE
- Broken ARIA reference
Try it
Tab to the gift-wrap box, then tick it and clear it with Space
Broken 1: listen to the box, empty and then ticked. Does the voice say what the box is for?
Broken 2: tick the box. Does the voice say what the box is, or whether it is ticked?
Apply a fix. Tick the box and clear it again. Does the voice say what the box is for, that it is a checkbox, and whether it is ticked?
Broken Can you fix this?
The fix
Write the ARIA as ARIA defines it, or use a native checkbox
Aria-labelledby pointing at an old id
<div class="tick-box" role="checkbox" aria-checked="false" aria-labelledby="gift-wrap-label" tabindex="0"></div><span id="giftwrap-label">Gift wrap this order</span>What is wrong3 points
The role and the state are right, and the tick is drawn. The name is where it fails.
- Nobody listening can tell what the box is for. A screen reader says only "checkbox, not checked".
- The checkbox has no name. A reference to an id that isn't on the page is skipped, and the words aren't inside the box to stand in for it.
- The reference points at nothing. The box points at
gift-wrap-label, and the label's id isgiftwrap-label.
The ARIA written as ARIA defines it
<div class="tick-box" role="checkbox" aria-checked="false" aria-labelledby="gift-wrap-label" tabindex="0"></div><span id="gift-wrap-label">Gift wrap this order</span>How it is fixed4 steps
- Give the box its role with
role="checkbox". - Point
aria-labelledbyat an id that is on the page, so the words beside the box become its name. - Keep
aria-checkedat"true"or"false", switched by Space and by a click. - Draw the tick from
aria-checkeditself, so what is shown and what is heard can't drift apart.
A screen reader says "Gift wrap this order, checkbox, not checked" and then "checked" after Space or a click. This fixes both Befores and passes 4.1.2. With the words inside the box, as in the second Before, the name comes from them, and role and aria-checked are enough. Where a template renders the option, build both ids from one value, so a rename changes both. The page must render aria-checked="true" when gift wrap is already chosen, for example in a saved basket.
A checkbox often stays a custom div for one of these reasons. Each can stay, as long as it leaves the role, the name and the state intact.
- A look of its own for the box and the tick: draw the tick from
aria-checked, as here, not from a class of its own. - A component library or framework that renders the box as a
div: keep the role, a name from an id that is on the page,aria-checkedand the Space key in what it renders. - A label placed apart from the box in the layout: build its id and the box's
aria-labelledbyfrom one value, so a rename changes both.
Why this fix: Style from the state, not a class
Both pass. The corrected ARIA fixes the component as it stands, but its role, the id its name comes from, its state, its Space key and its saved state are all yours to keep right, and every future edit can bring an invalid word or a stale id back. The native checkbox does the same job with no ARIA and no script: the label holds the input, so there is no id to keep in step and nothing left to misspell, and the browser keeps it working. Use it. Keep the corrected ARIA for a component you can't restructure yet.
Check what is rendered, not the template. Frameworks and components turn values into attributes in their own ways. A boolean prop may render as "true", as an empty attribute, or not at all, and a component may pass through whatever string it is given. Read the attribute in the browser's inspector after each change of state.
Other invalid ARIA that axe reports. The same failure takes other forms, each with its own rule. They share one fix: use the word ARIA defines for that place, or the native element that needs none.
- A value the attribute doesn't take, such as
aria-checked="yes"and"no"(aria-valid-attr-value). For an unknown value of a state exposed as on or off, ARIA tells browsers to treat anything other than an empty value or"undefined"as true, and Chrome does, so an empty box written as"no"is announced as checked. Use"true"and"false". - A role ARIA doesn't define, or an abstract one such as
role="input"orrole="widget"(aria-roles). Use the real role, such ascheckboxornavigation, or the HTML element, such asnav. - An attribute on a role that doesn't support it, such as
aria-checkedon a button (aria-allowed-attr). A button that stays pressed takesaria-pressed: see toggle buttons that don't say whether they are pressed. Thearia-checkedleft on adivbyaria-roleis reported here too. - ARIA that restates a native control's state, such as
aria-checkedon<input type="checkbox">, reported once it disagrees with the real state (aria-conditional-attr). Delete it: the browser uses the realcheckedeither way. - A deprecated role, such as
role="directory"(aria-deprecated-role). Uselist, orul. - A braille label with no name to go with it, such as
aria-braillelabelon an element with no other name (aria-braille-equivalent, sent for review). Give the element its ordinary name first.
ARIA that is defined but placed where it can't work. axe reports these too, each with its own fix.
- A role the element doesn't allow, such as
role="button"on anh3(aria-allowed-role). The role replaces the heading, which drops out of the headings list. Put abuttoninside the heading instead, as accordions that don't say whether a panel is open does. role="presentation"orrole="none"on an element that takes focus or has a global ARIA attribute such asaria-label(presentation-role-conflict). Browsers then ignore the role, so the element meant to be skipped is still read. Remove the role, or thetabindexand the attribute.role="text", which no ARIA version defines but Safari uses to read a group as one string, around a link or button (aria-text). VoiceOver can then read the control without its role while Tab still stops on it. Keep controls out of it.- An element with
role="tooltip"and no text in it (aria-tooltip-name). Put the tooltip's words inside it and tie it to its trigger witharia-describedby, as tooltips that vanish on approach and can't be dismissed shows.
A misspelling that works in some browsers. Chrome and Safari also accept aria-labeledby for aria-labelledby, but Firefox doesn't, so a label can look fine in Chrome and be missing in Firefox. axe reports it under aria-valid-attr; spell it with two Ls.
Ids that a template makes. Write each id once and build the reference from the same value, so a rename changes both, and write it without #. A template that renders the option more than once, such as once for each item in a basket, needs a different id for each copy: with two gift-wrap-labels on the page, every box is named by the first, and axe reports the repeat under duplicate-id-aria. Use the item's own id, or the framework's helper for it, such as React's useId(). The other references fail the same way when their id is missing. aria-describedby loses the description, and axe sends it for review, as it does aria-labelledby. aria-controls on a control that is expanded is reported under aria-valid-attr-value; while aria-expanded="false", axe doesn't check it.
Valid but wrong is covered elsewhere. A name on a div or span that can't hold one is in aria-label on divs and spans that screen readers often skip. A state left out altogether is in toggle switches that don't say whether they are on. aria-hidden on something that can take focus is in aria-hidden content that keyboard focus still reaches, and list roles without their items are in lists built from divs, icons and typed numbers.
Verify the fix
5 checks.
Test with: Screen reader, Keyboard, Mouse
Record the OS, browser and assistive-technology versions, the build, the date, and the actual result of each step. Repeat whenever the component or the code that saves its state changes.
Limits
This is a starting pattern, not a guarantee for every application. Class names are placeholders, and the checkbox stands for any custom control whose ARIA is written by hand. Browsers handle author errors in their own ways and change between versions, so a page that sounds right in one browser proves little. A custom box drawn beside a native checkbox hidden with display: none is a different failure, covered in custom checkboxes that keyboards and screen readers skip. A reference to an id that exists twice, because a component is shown more than once, finds the first copy; that is covered in duplicate ids that point labels at the wrong field. A name that exists but leaves out the words on screen is also a different failure, covered in buttons and links named differently from their text. Valid ARIA is not the same as correct ARIA: a scan that reports nothing can't tell you that a role suits the control or that its state follows the screen. Test the complete journey with your target assistive technology.
This is a recreated teaching example, not a finding about a named client. The code is a starting pattern: test it in your own product. No completed assistive-technology test is claimed here.
References
- WCAG Understanding: name-role-value (opens in a new tab)
- w3.org: wai-aria-1.2 (opens in a new tab)
- w3.org: wai-aria-1.2 (opens in a new tab)
- w3.org: wai-aria-1.2 (opens in a new tab)
- w3.org: accname-1.2 (opens in a new tab)
- w3.org: using-aria (opens in a new tab)
- developer.mozilla.org: checkbox_role (opens in a new tab)
- dequeuniversity.com: aria-valid-attr-value (opens in a new tab)
- dequeuniversity.com: aria-valid-attr (opens in a new tab)
- dequeuniversity.com: aria-roles (opens in a new tab)
- dequeuniversity.com: aria-toggle-field-name (opens in a new tab)
EaseWeb service
Fixed it? Keep it from coming back.
I turn guides like this one into rules your coding agents follow and checks your CI runs. Then I retest by hand with a keyboard and screen readers, periodically.