slop audit
Blog post 86 / Accessibility and visual design

Fix aria-allowed-attr errors: match ARIA to the role

Fix aria-allowed-attr errors by checking the rendered role, removing unsupported attributes, and testing a working toggle button with axe and Playwright.

By Slop Audit · 6 min read

An aria-allowed-attr error means an element has an ARIA attribute that its role does not support. Start with the rendered element and the exact attribute named in the finding. For example, a normal button with aria-selected="true" uses a real attribute and a valid value, but the attribute belongs to selection roles such as a tab. A two-state button uses aria-pressed instead. WAI-ARIA button role, WAI-ARIA selected state.

The repair is to align the control's purpose, role, state, and behavior. Changing the value from true to false leaves an unsupported attribute on the same element.

What aria-allowed-attr checks

ARIA defines supported states and properties for each role. Some properties are inherited or global; others apply only to particular roles. Axe's aria-allowed-attr rule checks whether the attributes are supported for the element's role. Check the role definition and the HTML element's permitted ARIA usage together. Deque rule reference, ARIA in HTML requirements.

Keep these adjacent errors separate when reading a report:

  • aria-allowed-attr: the attribute does not belong on this role.
  • aria-valid-attr: the attribute name is not recognized.
  • aria-valid-attr-value: the attribute's value fails its validation checks.
  • aria-required-attr: a role is missing a required attribute.

If the attribute is supported but the rendered value is malformed, use the aria-valid-attr-value troubleshooting guide. A control can have more than one defect, so rerun the checks after each repair. Deque axe rule index.

Trace the role and attribute in the rendered page

  1. Open the same route and UI state that produced the finding. Inspect the reported selector in browser DevTools.
  2. Record the element name, any explicit role, and the flagged attribute. Check the computed role in the accessibility pane. A native button already supplies a button role without an explicit role="button".
  3. Decide what the control actually does. Does it toggle a setting, select a tab, expand content, or navigate? Visual styling alone does not determine the role.
  4. Look up the supported attributes for that role. Include inherited states and properties, and check restrictions on the underlying HTML element.
  5. Trace the attribute back to the component that renders it. Inspect wrapper components, spread props, and conditional branches. A shared prop object can accidentally forward a tab's aria-selected to an ordinary button.

Do not add a role merely to make the attribute pass. Changing a button to role="tab" commits the component to tab behavior and its relationships with a tablist and panels. If it really switches between layered panels, follow the accessible tabs markup and keyboard guide. If it simply turns a filter on or off, keep a button.

Fix aria-allowed-attr on a toggle button

This filter button has the wrong state attribute:

<button type="button" aria-selected="false">
  Available only
</button>

For this example, pressing the button should filter a short product list. Keep the native button and use aria-pressed to expose whether the filter is active. Keep the accessible label stable while the state changes. W3C's button pattern describes toggle buttons and their Enter and Space activation. W3C button pattern.

<button id="availability" type="button" aria-pressed="false">
  Available only
</button>
<ul aria-label="Products">
  <li>Notebook — available</li>
  <li data-unavailable>Desk lamp — unavailable</li>
</ul>
<script type="module">
  const toggle = document.getElementById("availability");
  const unavailable = document.querySelectorAll("[data-unavailable]");

  toggle.addEventListener("click", () => {
    const active = toggle.getAttribute("aria-pressed") !== "true";
    toggle.setAttribute("aria-pressed", String(active));
    for (const item of unavailable) item.hidden = active;
  });
</script>

Remove aria-selected completely. Adding aria-pressed while leaving the unsupported attribute in place preserves the original failure. The example changes both the exposed state and the visible list; changing only ARIA would describe a filter that does not work.

In React or another framework, derive the pressed state and filtered results from one state owner. Check that a prop spread does not reintroduce the old attribute. Give an ordinary command button no toggle state at all. A button that submits a search once is different from a filter that stays on until pressed again.

Keep a visible cue for the active filter, such as a check mark or a clearly styled pressed state, and verify it remains understandable without color alone. Review the accessible name guide if an icon or tooltip changes what the control is called.

Test the repaired role, state, and behavior

The following Playwright test assumes /products renders the repaired example, your test project's baseURL points to that app, and @axe-core/playwright is installed. It checks both filter states rather than stopping when the initial axe scan passes.

import AxeBuilder from "@axe-core/playwright";
import { expect, test } from "@playwright/test";

test("availability filter uses a supported button state", async ({ page }) => {
  await page.goto("/products");
  const toggle = page.getByRole("button", { name: "Available only" });
  const lamp = page.getByText("Desk lamp — unavailable", { exact: true });

  await expect(toggle).toHaveAttribute("aria-pressed", "false");
  await expect(toggle).not.toHaveAttribute("aria-selected");
  await expect(lamp).toBeVisible();

  const checkRoleAttributes = async () => {
    const result = await new AxeBuilder({ page })
      .withRules(["aria-allowed-attr"])
      .analyze();
    expect(result.violations).toEqual([]);
  };
  await checkRoleAttributes();

  await page.keyboard.press("Tab");
  await expect(toggle).toBeFocused();
  await page.keyboard.press("Enter");
  await expect(toggle).toHaveAttribute("aria-pressed", "true");
  await expect(lamp).toBeHidden();
  await checkRoleAttributes();

  await page.keyboard.press("Space");
  await expect(toggle).toHaveAttribute("aria-pressed", "false");
  await expect(lamp).toBeVisible();
  await expect(toggle).toBeFocused();
});

The isolated example makes this button the first tab stop. On a full route, tab through the preceding controls and assert the expected path. Avoid forcing a click just to get past an unreachable control. Add the scenario to your website regression testing checklist, and run your broader accessibility suite separately: this targeted rule cannot establish that the whole page is accessible. Playwright accessibility testing.

Manually verify the stable name, button role, and changing pressed state with a screen reader. Check that filtering preserves a sensible focus position and that people can discover which results remain. A passing attribute check does not assess those outcomes.

Recheck the deployed page with Slop Audit

After deploying the repair, run a Slop Audit on the public route. When browser evidence is available, open Accessibility violations and inspect the observed axe rule IDs and selectors. An aria-allowed-attr finding can direct you back to a role/attribute mismatch that survived the build.

Rescan the same URL after fixing it and retain the behavior test for the filter's active state. Slop Audit samples the public page in a limited browser run; it does not exhaust every interaction or replace a screen-reader review. Use the report to locate observed failures, then verify the complete task before launch.