Tailwind CSS fix

Before and after

Broken — before
<!-- Broken Tailwind icon button: missing sr-only label and decorative SVG flags -->
<button
  type="button"
  class="inline-flex h-10 w-10 items-center justify-center rounded-lg border border-slate-300 bg-white text-slate-900 hover:bg-slate-50"
>
  <svg class="h-5 w-5" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
    <path stroke-linecap="round" stroke-linejoin="round" d="M4 6h16M4 12h16M4 18h16" />
  </svg>
</button>
Fixed — after
<!-- Fixed Tailwind icon button: built-in sr-only text + aria-hidden SVG + focus ring -->
<button
  type="button"
  class="inline-flex h-10 w-10 items-center justify-center rounded-lg border border-slate-400 bg-white text-slate-900 hover:bg-slate-50 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-sky-700"
>
  <span class="sr-only">Open main navigation menu</span>
  <svg class="h-5 w-5" aria-hidden="true" focusable="false" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
    <path stroke-linecap="round" stroke-linejoin="round" d="M4 6h16M4 12h16M4 18h16" />
  </svg>
</button>
Live preview

Fixed vs. broken example

Passes button-name
Accessibility tree: role="button", accessible name="Open site search" (decorative SVG hidden with aria-hidden="true")

Tab to each button and inspect the Accessibility pane in DevTools: the broken control exposes an empty Name while the fixed control exposes "Open site search".

Automated test

Playwright + axe-core check

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

test("Tailwind sr-only navigation toggle passes button-name", async ({ page }) => {
  await page.setViewportSize({ width: 390, height: 844 });
  await page.goto("/");
  await expect(
    page.getByRole("button", { name: "Open main navigation menu" })
  ).toBeVisible();
  const results = await new AxeBuilder({ page })
    .withRules(["button-name"])
    .analyze();
  expect(results.violations).toEqual([]);
});

Template deduplication tip

A single Tailwind mobile-drawer toggle button copied into a shared navigation partial fires across every route. A11yDrift clusters all of those nav hits under one header landmark so adding one sr-only span clears the whole domain.

Screen readers

What NVDA and VoiceOver announce

Blind screen-reader users and voice-dictation users (Dragon, Voice Control) encounter unlabeled icon buttons as generic 'button' controls with no clue whether activating them opens search, closes a modal, or deletes an item.

NVDA (Windows)

Broken

"button" (silence — no action name announced)


Fixed

"Open site search, button"

VoiceOver (macOS / iOS)

Broken

"button" (unlabeled interactive element)


Fixed

"Open site search, button"

Common questions

Is Tailwind's sr-only class better than display: none (hidden)?
Yes—Tailwind's hidden (display: none) removes the text from the Accessibility Tree completely, causing button-name to fail. Tailwind's sr-only visually clips the text to 1px while keeping it readable by every screen reader.
Does sr-only work with automated page translators better than aria-label?
Often yes. Browser translation extensions reliably translate visible DOM text inside <span class='sr-only'>, whereas some translators occasionally skip aria-label attributes.
What minimum touch-target size should Tailwind icon buttons use for WCAG 2.2 AA?
WCAG 2.2 SC 2.5.8 Target Size (Minimum) requires at least 24×24 CSS px (h-6 w-6), and 40×40 to 44×44 px (h-10 w-10 or h-11 w-11) is recommended for comfortable mobile tapping.