Fix button-name in Tailwind CSS
Tailwind UI and Headless UI icon buttons often drop their <span class='sr-only'> label when developers copy-paste markup and delete the inner span to tweak spacing. Keeping either Tailwind's sr-only text or an explicit aria-label ensures screen readers announce the exact action while preserving a clean minimal icon layout.
Before and after
<!-- 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 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>Fixed vs. broken example
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".
Playwright + axe-core check
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.
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)
"button" (silence — no action name announced)
"Open site search, button"
VoiceOver (macOS / iOS)
"button" (unlabeled interactive element)
"Open site search, button"
Common questions
Is Tailwind's sr-only class better than display: none (hidden)?
Does sr-only work with automated page translators better than aria-label?
What minimum touch-target size should Tailwind icon buttons use for WCAG 2.2 AA?
Test a URL for button-name
Enter any public URL for a free WCAG 2.2 AA check—no account or credit card required.
Shipping Tailwind CSS weekly? Block new button-name regressions in PRs with our baseline-diff GitHub Action PR gate (≤20 URLs/PR).