Check 40.06 · AI agent compatibility

Make component states accessible

Expose the state of menus, tabs, options, steps and loading with native HTML and ARIA, so that an AI agent knows whether its click worked and what to do next.

Priority
Experimental
Difficulty
Intermediate
Estimated time
2 h to 2 days
Free, no account: your progress is saved in this browser.

Ask an AI to check this point on your site

Opens the assistant with a ready-made question: this check, its goal and your site URL.

For Gemini, Copilot or another assistant, copy the question. The link opens the chosen service directly: nothing goes through this site.

In short

An interactive component has a state: a menu is open or closed, an option is selected, a step is in progress, a button is disabled, a cart is being updated. This state must be visible on screen and exposed in the code, through the native HTML element or the corresponding ARIA (Accessible Rich Internet Applications) attribute. Once this check is done, after every click, the accessibility tree and the display say the same thing: what changed, and what is possible now. This topic is experimental: no agent documents exactly which states it reads.

Why it matters

An agent acting on a page follows a loop: observe, act, observe again to check. The documentation of Anthropic's computer use tool recommends having the model check the result of each action, precisely because it sometimes assumes an action succeeded without verifying it. That check is only possible if the state changes in a readable way.

When the state is purely visual (an arrow that rotates, a colored border, a grayed-out swatch), an agent reading the accessibility tree sees no difference between before and after its click. It tries again, closes what it had just opened, picks a sold-out size or submits the order twice because nothing showed it was in progress. Conversely, aria-expanded="true", a checked box, aria-current="step" or an “Updating cart…” message in a role="status" area appear as such in the tree: Playwright MCP, for example, renders these states in its page snapshots.

WCAG (Web Content Accessibility Guidelines) success criterion 4.1.2 “Name, Role, Value” requires the states and properties of components to be programmatically determinable, and criterion 4.1.3 requires status messages to be announced without moving focus.

What it improves

  • Agent reliability Fewer repeated clicks, sold-out options chosen or duplicate submissions. A plausible effect, not publicly measured.
  • Accessibility Screen readers announce “collapsed”, “expanded”, “selected”, “current page”. Compliance with 4.1.2 and 4.1.3.
  • Code quality A single state, carried by the attribute, can also drive the styling ([aria-expanded="true"] in CSS), which avoids mismatches between display and code.
  • Automated tests Tests can check a state rather than a CSS class.
  • Rankings No direct effect.

How to check

Before and after each action. On key pages, select the menu, tab, color swatch or button in Chrome (Elements panel, Accessibility tab), note its computed properties, click, then read them again. A property must have changed: Expanded, Selected, Checked, Pressed, Disabled, Busy, or the name.

Compared snapshots. With the ARIA snapshot script from the guide use semantic HTML and explicit labels (opens in a new tab), capture the page, click, then capture it again. Compliant excerpt after opening the menu and choosing a size:

- button "Menu" [expanded]
- navigation "Main menu":
  - link "Women"
- group "Size":
  - radio "40" [checked]
  - radio "41 (sold out)" [disabled]
- status: "Cart updated: 2 items"

Automated audit. axe DevTools flags invalid or misused ARIA attributes (aria-allowed-attr, aria-valid-attr-value); it does not detect a state that fails to change. That check remains manual.

How to implement

Before you start

Choose the native element first, which manages the state without code; ARIA comes second:

Component Native (state managed by the browser) With ARIA
Collapsible section, FAQ <details> and <summary> <button aria-expanded aria-controls>
Drop-down menu, filter panel — <button aria-expanded="false" aria-controls="id">
Modal dialog <dialog> opened with showModal() role="dialog" aria-modal="true"
Single choice (size, color) <input type="radio"> in a <fieldset> role="radiogroup" + aria-checked
Multiple choice, switch <input type="checkbox"> role="switch" aria-checked
Toggle button (favorite, quick filter) — <button aria-pressed="true">
Tabs — role="tablist", role="tab" aria-selected, role="tabpanel"
Current page or step — aria-current="page" or aria-current="step"
Unavailable action disabled attribute aria-disabled="true" if the button must remain focusable to explain why
Loading, updating — aria-busy="true" on the area, message in role="status"
Hidden content hidden attribute, inert for the background of a modal —
Table sorting — aria-sort="ascending" on the sorted header

Rules:

  • A single source of truth for the state: the attribute. The styling derives from it (button[aria-expanded="true"] .icone { transform: rotate(180deg); }) rather than from a separate CSS class that someone forgets to keep in sync.
  • The visible state does not rely on color alone: a sold-out option is struck through and carries the text “sold out”.
  • The name does not change with the state for toggles: “Add to favorites” with aria-pressed, not “Add” then “Remove” with no state.
  • The results of an asynchronous action (adding to cart, applying a code, filtering) are announced in a role="status" area that is present from page load, empty at first.
  • An unavailable option says so: disabled on the sold-out size's radio button and visible text, rather than a clickable swatch that does nothing.

Ready-to-paste template: size selector, add button with a loading state, and a status area.

<form action="/panier" method="post" id="ajout-panier">
  <fieldset>
    <legend>Size</legend>
    <input type="radio" id="t40" name="taille" value="40" checked>
    <label for="t40">40</label>
    <input type="radio" id="t41" name="taille" value="41" disabled>
    <label for="t41">41 <span>(sold out)</span></label>
    <input type="radio" id="t42" name="taille" value="42">
    <label for="t42">42</label>
  </fieldset>

  <button type="submit" id="bouton-ajout">Add to cart</button>
  <p role="status" id="statut-panier"></p>
</form>

<script>
  document.getElementById('ajout-panier').addEventListener('submit', async (event) => {
    event.preventDefault();
    const formulaire = event.currentTarget;
    const bouton = document.getElementById('bouton-ajout');
    const statut = document.getElementById('statut-panier');

    bouton.setAttribute('aria-disabled', 'true');
    formulaire.setAttribute('aria-busy', 'true');
    statut.textContent = 'Adding to cart…';

    const reponse = await fetch(formulaire.action, { method: 'POST', body: new FormData(formulaire) });
    const panier = await reponse.json();

    formulaire.removeAttribute('aria-busy');
    bouton.removeAttribute('aria-disabled');
    statut.textContent = reponse.ok
      ? `Item added. Your cart contains ${panier.quantite} items.`
      : `The item was not added: ${panier.message}`;
  });
</script>

Drop-down menu with a button and a state:

<button type="button" aria-expanded="false" aria-controls="menu-produits">Products</button>
<ul id="menu-produits" hidden>
  <li><a href="/chaussures">Shoes</a></li>
  <li><a href="/vestes">Jackets</a></li>
</ul>

<script>
  const declencheur = document.querySelector('[aria-controls="menu-produits"]');
  declencheur.addEventListener('click', () => {
    const ouvert = declencheur.getAttribute('aria-expanded') === 'true';
    declencheur.setAttribute('aria-expanded', String(!ouvert));
    document.getElementById('menu-produits').hidden = ouvert;
  });
</script>

For complete patterns (tabs, accordion, modal, combobox), follow the W3C's APG (ARIA Authoring Practices Guide), and the rules in use ARIA when necessary (opens in a new tab).

Good to know: an element hidden with display: none, hidden or inert disappears from the accessibility tree. That is intended for a closed menu, but essential information (price, conditions) must not depend on something being opened: see make content accessible without user interaction (opens in a new tab).

WordPress

Versions WordPress 6.5 and later, block editor, WooCommerce 9 and 10, November 2026.

  • Details block: it outputs <details> and <summary>, with an open or closed state managed by the browser. Prefer it to plugin accordions for FAQs.
  • Navigation block: the mobile menu button and the submenus carry aria-expanded. In the block settings, make submenus open on click rather than on hover.
  • WooCommerce: on variable products, unavailable combinations are flagged by the variations form; if a swatch plugin (color, size) replaces the drop-down lists, check that it exposes the selected state and the unavailable state in the accessibility tree, not just through a CSS class.
  • Page builders: check Tabs and Accordion widgets in the Accessibility tab; some expose neither aria-selected nor aria-expanded.

Shopify

Versions Online Store 2.0 themes, Liquid, November 2026.

Shopify's Online Store 2.0 themes use <details> and <summary> for menus and filters, and radio buttons for product options. In a custom section, keep this principle and expose unavailability:

<fieldset>
  <legend>{{ option.name }}</legend>
  {% for value in option.values %}
    <input type="radio" id="{{ section.id }}-{{ option.position }}-{{ forloop.index0 }}"
      name="{{ option.name }}" value="{{ value | escape }}"
      {% if option.selected_value == value %}checked{% endif %}
      {% unless value.available %}disabled{% endunless %}>
    <label for="{{ section.id }}-{{ option.position }}-{{ forloop.index0 }}">
      {{ value }}{% unless value.available %} <span>(sold out)</span>{% endunless %}
    </label>
  {% endfor %}
</fieldset>

After adding to the cart through the Ajax API, update the cart counter and announce the result in a role="status" area.

Laravel

Versions Laravel 11 to 13.

With Alpine.js, bind the ARIA state to the same variable as the display:

<div x-data="{ ouvert: false }">
    <button type="button" @click="ouvert = ! ouvert" :aria-expanded="ouvert.toString()" aria-controls="filtres">
        Filters
    </button>
    <div id="filtres" x-show="ouvert" x-cloak>
        {{-- filter fields --}}
    </div>
</div>

With Livewire, wire:loading.attr="aria-busy" on the updated area and a message in role="status" (<p role="status" wire:loading>Updating…</p>) expose the loading state. For a step in a checkout flow, add aria-current="step" to the active step in the Blade loop.

Next.js

Versions Next.js 15 and 16 (App Router).

Derive the attributes from the React state, without duplicating it:

'use client';

import { useState } from 'react';
import { usePathname } from 'next/navigation';
import Link from 'next/link';

export function MenuCategories({ categories }: { categories: { href: string; nom: string }[] }) {
  const [ouvert, setOuvert] = useState(false);
  const chemin = usePathname();

  return (
    <nav aria-label="Categories">
      <button type="button" aria-expanded={ouvert} aria-controls="liste-categories" onClick={() => setOuvert(!ouvert)}>
        Categories
      </button>
      <ul id="liste-categories" hidden={!ouvert}>
        {categories.map((categorie) => (
          <li key={categorie.href}>
            <Link href={categorie.href} aria-current={chemin === categorie.href ? 'page' : undefined}>{categorie.nom}</Link>
          </li>
        ))}
      </ul>
    </nav>
  );
}

For rich components (tabs, combobox, modals), the Radix, React Aria or Headless UI libraries manage ARIA states; check the result in the accessibility tree. For a form with a Server Action, useFormStatus provides the pending state to display in the button and the status area.

Common mistakes

  • State carried by a CSS class alone (.is-open, .active): invisible in the accessibility tree.
  • aria-expanded set on the panel instead of the button that opens it.
  • A frozen attribute: aria-expanded="false" hard-coded and never updated.
  • Variant swatches made of <div> elements: no role, no selected state, no unavailability.
  • A role="status" area created at the moment of the message: often not announced. It must exist before it is filled.
  • A disabled button with no explanation: prefer aria-disabled="true" with a message, or leave it active and explain the error on submission (see provide clear error messages (opens in a new tab)).
  • Double submission: no “in progress” state during processing, so the agent or the user clicks twice.

Frequently asked questions

Why does a component's state matter to an AI agent?

An AI agent checks the result of each action before moving on to the next. If a menu opens or a size is selected without the accessibility tree or the page text changing, the agent does not know whether its click worked. It tries again, undoes its action or picks the wrong option. A state exposed through native HTML or ARIA gives it that confirmation.

What is the difference between disabled and aria-disabled?

The disabled attribute actually deactivates the element: it no longer receives focus, no longer responds and is not submitted with the form. The aria-disabled="true" attribute only announces the state: the element remains focusable, and your code has to block the action. Use aria-disabled when the user or the agent must be able to reach the button to read why the action is unavailable.

Should you use details and summary for accordions?

It is the simplest solution for a collapsible section or an FAQ. The browser handles opening on click and with the keyboard, and exposes the expanded or collapsed state without JavaScript or ARIA attributes. The content stays in the HTML. A JavaScript accordion is only justified if you need a behavior that details does not allow, such as a complex animation.

How do you announce an item added to the cart without reloading the page?

Place an empty paragraph with role="status" in the page from the moment it loads. After the item is added, write a complete message in it, for example “Item added, your cart contains 2 items”. Screen readers announce it without moving focus, and an AI agent finds it in the page text and the accessibility tree. Also update the visible cart counter.

Updated on

Topic checklist (PDF)

And now?

In the “AI agent compatibility” topic

  1. Use semantic HTML and explicit labels
  2. Identify what each button does
  3. Provide clear error messages
  4. Keep URLs stable
  5. Avoid mandatory complex gestures
  6. Make component states accessible
  7. Display final prices, availability and options
  8. Simplify booking and checkout
  9. Document existing public APIs
  10. Use OpenAPI if relevant
  11. Evaluate MCP based on use cases
  12. Evaluate compatible agentic commerce protocols
  13. Check authentication and authorization
  14. Require confirmation for sensitive actions
  15. Test user journeys with browsing agents
  16. Prevent prompt injection and unauthorized interactions