Tailwind CSS fix

Before and after

Broken — before
<!-- Broken Tailwind tab bar: extra flex wrapper <div> inside role="tablist" -->
<div role="tablist" aria-label="Billing interval" class="inline-flex rounded-lg bg-slate-100 p-1">
  <div class="flex items-center gap-1">
    <button type="button" class="rounded-md bg-white px-3 py-1.5 text-sm font-medium text-slate-900">
      Monthly
    </button>
    <button type="button" class="rounded-md px-3 py-1.5 text-sm font-medium text-slate-600">
      Annual
    </button>
  </div>
</div>
Fixed — after
<!-- Fixed Tailwind tab bar: direct role="tab" children + aria-selected styling -->
<div role="tablist" aria-label="Billing interval" class="inline-flex items-center gap-1 rounded-lg bg-slate-100 p-1">
  <button
    type="button"
    role="tab"
    aria-selected="true"
    class="rounded-md px-3 py-1.5 text-sm font-semibold text-slate-700 aria-selected:bg-white aria-selected:text-slate-950 aria-selected:shadow-xs"
  >
    Monthly
  </button>
  <button
    type="button"
    role="tab"
    aria-selected="false"
    tabindex="-1"
    class="rounded-md px-3 py-1.5 text-sm font-semibold text-slate-700 aria-selected:bg-white aria-selected:text-slate-950 aria-selected:shadow-xs"
  >
    Annual (Save 20%)
  </button>
</div>
Live preview

Fixed vs. broken example

Passes aria-required-children
Accessibility tree: role="tablist" directly owns role="tab" (selected, 1 of 2) and role="tab" (unselected, 2 of 2)

Remove extraneous intermediate wrapper <div>s between a composite ARIA parent and its required children—or set role="none" on purely structural wrappers.

Automated test

Playwright + axe-core check

tests/a11y-aria-required-children.spec.ts
import { test, expect } from "@playwright/test";
import AxeBuilder from "@axe-core/playwright";

test("Tailwind tablist uses direct role=tab children", async ({ page }) => {
  await page.goto("/pricing");
  const results = await new AxeBuilder({ page })
    .withRules(["aria-required-children"])
    .analyze();
  expect(results.violations).toEqual([]);
});

Template deduplication tip

A shared Tailwind pricing-period toggle or filter listbox reused across marketing and app routes generates repeated aria-required-children errors—fixing the one shared markup pattern resolves every page.

Screen readers

What NVDA and VoiceOver announce

When a container declares role='tablist', role='menu', or role='listbox' without directly owning its required child roles (tab, menuitem, option), assistive technologies break arrow-key navigation, item counts ('1 of 3'), and selection state announcements.

NVDA (Windows)

Broken

"Product details, tab control" -> "Specs, button" (item count and selected tab semantics lost)


Fixed

"Product details, tab control, Specs, tab, selected, 1 of 2"

VoiceOver (macOS / iOS)

Broken

"Product details, tab group, 0 items" -> "Specs, button"


Fixed

"Specs, selected, tab, 1 of 2, Product details, tab group"

Common questions

Why does Tailwind Preflight cause people to add role='list' to <ul>?
Tailwind's Preflight sets list-style: none, which causes Safari VoiceOver to omit list semantics unless role='list' is added. If you add role='list' to a <ul>, make sure every direct child is a <li> (not a stray <div> or heading).
Can Tailwind style active ARIA states without extra wrapper classes?
Yes—Tailwind ships native aria-selected:, aria-expanded:, aria-checked:, and aria-current: variants so your visual styles stay strictly coupled to valid ARIA attributes.
Do I still need arrow-key keyboard support when using role='tablist'?
Yes. Automated axe-core checks verify the static ARIA hierarchy, while manual keyboard testing confirms Left/Right Arrow moves focus across tabs per the WAI-ARIA Authoring Practices Guide.

Fix aria-required-children in other stacks

More Tailwind CSS guides