Fix select-name in Tailwind CSS
Tailwind filter bars and footer locale switchers often render sleek border-slate-200 <select> dropdowns with no <label> element. Adding a paired <label for='...'> (visible or sr-only inside compact toolbars) plus a 3:1 visible border (border-slate-400) passes select-name and improves usability across mouse and keyboard.
Before and after
<!-- 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 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>Fixed vs. broken example
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.
Playwright + axe-core check
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.
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)
"combo box, Featured, collapsed" (purpose of selector unknown)
"Sort products by, combo box, Featured, collapsed"
VoiceOver (macOS / iOS)
"Featured, pop-up button"
"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>?
<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?
Does native <select> beat custom Tailwind div dropdowns for accessibility?
Test a URL for select-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 select-name regressions in PRs with our baseline-diff GitHub Action PR gate (≤20 URLs/PR).