Tailwind CSS fix

Before and after

Broken — before
<!-- Broken Tailwind toolbar dropdown: no <label> or aria-label -->
<div class="flex items-center gap-2">
  <select class="rounded-md border border-slate-300 bg-white px-3 py-2 text-sm text-slate-900">
    <option value="en-US">English (US)</option>
    <option value="de-DE">Deutsch (EU)</option>
    <option value="fr-FR">Français (EU)</option>
  </select>
</div>
Fixed — after
<!-- Fixed Tailwind toolbar dropdown: explicit <label for> + focus-visible ring -->
<div class="flex items-center gap-2">
  <label for="locale-select" class="text-sm font-medium text-slate-800">
    Language
  </label>
  <select
    id="locale-select"
    name="locale"
    class="rounded-md border border-slate-400 bg-white px-3 py-2 text-sm text-slate-900 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-sky-700"
  >
    <option value="en-US">English (US)</option>
    <option value="de-DE">Deutsch (EU)</option>
    <option value="fr-FR">Français (EU)</option>
  </select>
</div>
Live preview

Fixed vs. broken example

Passes select-name
Accessibility tree: role="combobox", accessible name="Sort products by", value="Featured"

Avoid relying on a dummy first <option> like "Sort by..." as the sole label; once a user picks an option, the purpose disappears for everyone.

Automated test

Playwright + axe-core check

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

test("Tailwind language and sort <select> menus pass select-name", async ({ page }) => {
  await page.goto("/");
  await expect(page.getByLabel("Language")).toBeVisible();
  const results = await new AxeBuilder({ page })
    .withRules(["select-name"])
    .analyze();
  expect(results.violations).toEqual([]);
});

Template deduplication tip

A single unlabeled Tailwind locale or sort <select> inside a shared navbar or filter bar generates repeated alerts across every route—fixing that component markup clears all affected pages.

Screen readers

What NVDA and VoiceOver announce

E-commerce variant pickers (Size, Color), collection sort dropdowns, and country selectors without a programmatic <label> or aria-label announce only the first option ('Featured' or 'Small'), hiding what the dropdown controls.

NVDA (Windows)

Broken

"combo box, Featured, collapsed" (purpose of selector unknown)


Fixed

"Sort products by, combo box, Featured, collapsed"

VoiceOver (macOS / iOS)

Broken

"Featured, pop-up button"


Fixed

"Sort products by, Featured, pop-up button"

Common questions

Can I use Tailwind's sr-only class on a <label> for a compact filter <select>?
Yes—<label for='sort-by' class='sr-only'>Sort results</label> keeps tight horizontal toolbars visually uncluttered while exposing a reliable accessible name to NVDA, VoiceOver, and axe-core.
Why avoid removing the native focus outline with focus:outline-none in Tailwind?
Removing outline without adding a high-contrast replacement ring violates WCAG 2.4.7 Focus Visible. Always pair clean Tailwind controls with focus-visible:outline-2 focus-visible:outline-offset-2.
Does native <select> beat custom Tailwind div dropdowns for accessibility?
For standard option lists, native <select> gives you free type-ahead search, mobile OS pickers, Escape/Arrow-key handling, and zero ARIA-children bugs.