In short
A visitor navigating with the keyboard must be able to reach the language switcher with the Tab key, see where the focus is, open the list, choose a language with Enter, close the list with Escape, and never get stuck. The task is to run this test on each template and on mobile, then fix the component: real links, a disclosure button (a button that shows or hides the list), visible focus, and no page change from merely moving through a list. Once the task is done, switching language with the keyboard takes a few keystrokes and works without a mouse.
Why it matters
The language switcher is often the least tested component on a site: small, placed in the header, built by a plugin or a theme. Yet it combines several traps:
- a globe icon or a flag in a clickable
<div>, which the Tab key never reaches; - a list that only opens on mouse hover;
- a
<select>that changes page as soon as an arrow key is pressed, before a choice has even been made; - an open menu that cannot be closed, or that you can no longer get out of;
- a focus outline removed by the CSS (
outline: none).
The WCAG (Web Content Accessibility Guidelines) success criteria involved apply directly: 2.1.1 Keyboard and 2.1.2 No Keyboard Trap (level A), 2.4.3 Focus Order (A), 2.4.7 Focus Visible (AA), 2.4.11 Focus Not Obscured (AA, added in WCAG 2.2), 3.2.2 On Input (A), 3.1.2 Language of Parts (AA) and 4.1.2 Name, Role, Value (A). In France, the RGAA (Référentiel général d'amélioration de l'accessibilité) incorporates these requirements. A visitor who cannot switch language leaves the site, or reads a language they understand poorly.
The link with visibility is indirect but real: a switcher made of real <a href> links, named and present in the HTML, is at once keyboard accessible, crawlable by crawlers and readable by AI agents that navigate using the accessibility tree.
What it improves
- Accessibility Visitors using a keyboard, a screen reader or a switch can change language.
- Compliance Meets the WCAG and RGAA criteria listed above, which are often audited.
- Crawling A switcher made of real links is followed by crawlers. See provide a crawlable language switcher (opens in a new tab).
- AI agents A named, operable component can be used by an agent browsing on behalf of a user. A possible effect, not measured.
- Rankings No direct effect.
How to check
Unplug the mouse, or stop touching it, and follow this grid on one page per language, in a wide window and then in a narrow one (mobile menu):
| Step | Action | Expected result |
|---|---|---|
| 1. Reach | Tab from the top of the page | The switcher receives focus in a logical order (after the logo and navigation, or within the header) |
| 2. See | Watch the focus | Clear, visible outline, not hidden by a sticky header |
| 3. Understand | Read the label | Explicit name ("Language: English"), not just a flag or a globe |
| 4. Open | Enter or Space on the button | The list appears; the screen reader announces "expanded" |
| 5. Browse | Tab through the list | Each language receives focus; the page does not change until something is confirmed |
| 6. Choose | Enter on a language | The equivalent page opens in that language |
| 7. Close | Escape | The list closes, focus returns to the button |
| 8. Leave | Tab after the last language | Focus moves to the next element; the list closes |
| 9. Announce | Screen reader | The current language is indicated, each name is pronounced in its own language |
Other checks:
- Tab order visualization: Accessibility Insights for Web shows the focus path ("Tab stops" feature); axe DevTools and Lighthouse flag elements without a name or with incorrect roles. See test with axe, WAVE or Lighthouse (opens in a new tab).
- Screen reader: NVDA on Windows, VoiceOver on macOS (Cmd + F5). Check how the button is announced ("Language, button, collapsed") and how "Deutsch" or "Français" is pronounced.
- Code: in the switcher's HTML, look for interactive elements with neither
hrefnor<button>(<div onclick>,<span>), positivetabindexvalues andoutline: nonerules with no replacement.
For keyboard navigation across the rest of the site, see test keyboard navigation (opens in a new tab).
How to implement
Before you start
The recommended pattern is the disclosure button described in the W3C ARIA Authoring Practices Guide (APG): a <button> with aria-expanded that shows a list of links. The APG points out that its site navigation example does not use the menu role: navigation does not need the complex interactions (arrow keys, submenus) that the menu and menuitem roles require.
Markup, valid for every environment:
<nav class="lang-switcher" aria-label="Language">
<button type="button" class="lang-switcher__toggle" aria-expanded="false" aria-controls="lang-menu" hidden>
<span class="visually-hidden">Language:</span> Français
</button>
<ul id="lang-menu" class="lang-switcher__menu">
<li><a href="https://example.com/fr/tarifs/" hreflang="fr" lang="fr" aria-current="page">Français</a></li>
<li><a href="https://example.com/de/preise/" hreflang="de" lang="de">Deutsch</a></li>
<li><a href="https://example.com/en/pricing/" hreflang="en" lang="en">English</a></li>
</ul>
</nav>
Without JavaScript, the button stays hidden and the list of links is displayed: the switcher still works. The script enables the disclosure, closing with Escape, and closing when focus leaves the component:
document.querySelectorAll('.lang-switcher').forEach((switcher) => {
const toggle = switcher.querySelector('.lang-switcher__toggle');
const menu = switcher.querySelector('.lang-switcher__menu');
const close = (returnFocus) => {
toggle.setAttribute('aria-expanded', 'false');
menu.hidden = true;
if (returnFocus) {
toggle.focus();
}
};
toggle.hidden = false;
menu.hidden = true;
toggle.addEventListener('click', () => {
const isOpen = toggle.getAttribute('aria-expanded') === 'true';
toggle.setAttribute('aria-expanded', String(!isOpen));
menu.hidden = isOpen;
});
switcher.addEventListener('keydown', (event) => {
if (event.key === 'Escape' && !menu.hidden) {
close(true);
}
});
switcher.addEventListener('focusout', (event) => {
if (!switcher.contains(event.relatedTarget)) {
close(false);
}
});
});
And the minimal CSS:
.lang-switcher a:focus-visible,
.lang-switcher button:focus-visible {
outline: 3px solid #1a56db;
outline-offset: 2px;
}
.visually-hidden {
position: absolute;
width: 1px;
height: 1px;
overflow: hidden;
clip: rect(0 0 0 0);
white-space: nowrap;
}
html {
scroll-padding-top: 5rem;
}
scroll-padding-top keeps a sticky header from hiding the element that receives focus; adjust the value to the header's height. Check the outline's contrast against the header background.
Rules to follow:
- No page change on movement: a
<select>list that navigates on thechangeevent may change page from the first arrow key press depending on the browser and operating system, which fails success criterion 3.2.2. If you keep a<select>, add a "Go" button and only navigate when it is activated. - Each language's name in that language, with the
langattribute on each link: the screen reader pronounces it correctly. - Current language indicated by
aria-current="page"on its link, or by the button's label. - No positive
tabindex: focus order follows the HTML order; place the switcher where you want it in the code.
An acceptable script-free variant: <details> and <summary>, which open natively with the keyboard. Escape does not close them without a script: test whether this behavior suits you.
WordPress
Versions WordPress 6.4 and later; Polylang 3, WPML 4 and 5, TranslatePress, November 2026.
- Polylang: the "Language switcher" block or widget offers a list display or a dropdown display. The list produces links and should be preferred. The dropdown relies on a
<select>that changes page when its value changes: test it with the keyboard using the grid, and switch back to the list if the page changes from the first arrow key press. - WPML: switchers (menu, widget, footer) are configured in
WPML > Settings, language switcher section, from WPML 5 onward (inWPML > Languageswith WPML 4). Test the "drop-down" style with the keyboard: depending on the theme, it only opens on hover. The horizontal and vertical list styles produce plain links. - TranslatePress: the floating switcher and the
[language-switcher]shortcode need to be tested the same way. - Custom theme: generate the markup from the "Before you start" section using the plugin's data (
pll_the_languages(['raw' => 1])for Polylang, thewpml_active_languagesfilter for WPML), then add the script and the CSS to the child theme.
Finally, check that the theme does not remove the focus outline globally (*:focus { outline: none; }), then purge the cache.
Shopify
Versions Online Store 2.0 themes, all Shopify plans, November 2026.
Recent themes build the language switcher with a disclosure button and a list inside the localization form. Run the keyboard grid on the header, the footer and the mobile menu, which are often three separate components. If a switcher fails, edit the relevant snippet or section file in Online Store > Themes > Edit code (search for localization in the files), keeping a <button aria-expanded> and focusable elements for each language. Elements added by translation apps must be tested separately.
Laravel
Versions Laravel 11 to 13.
Put the markup in a Blade component and generate links to the equivalent route in each language:
{{-- resources/views/components/language-switcher.blade.php --}}
@php
$languages = ['fr' => 'Français', 'de' => 'Deutsch', 'en' => 'English'];
$current = app()->getLocale();
@endphp
<nav class="lang-switcher" aria-label="{{ __('Language') }}">
<button type="button" class="lang-switcher__toggle" aria-expanded="false" aria-controls="lang-menu" hidden>
<span class="visually-hidden">{{ __('Language:') }}</span> {{ $languages[$current] }}
</button>
<ul id="lang-menu" class="lang-switcher__menu">
@foreach($languages as $code => $name)
<li>
<a href="{{ route(Route::currentRouteName(), ['locale' => $code] + request()->route()->parameters()) }}" hreflang="{{ $code }}" lang="{{ $code }}" @if($code === $current) aria-current="page" @endif>{{ $name }}</a>
</li>
@endforeach
</ul>
</nav>
Add the script from the "Before you start" section to the Vite bundle. If slugs are translated, replace the URL construction with the translation's route.
Next.js
Versions Next.js 15 and 16 (App Router).
A client component is rendered on the server in the initial HTML, then hydrated: the links stay present for crawlers.
// app/[lang]/language-switcher.tsx
'use client';
import { useRef, useState } from 'react';
type Language = { code: string; name: string; href: string };
export function LanguageSwitcher({ current, languages }: { current: string; languages: Language[] }) {
const [open, setOpen] = useState(false);
const toggleRef = useRef<HTMLButtonElement>(null);
const currentName = languages.find((language) => language.code === current)?.name;
return (
<nav
className="lang-switcher"
aria-label="Language"
onKeyDown={(event) => {
if (event.key === 'Escape' && open) {
setOpen(false);
toggleRef.current?.focus();
}
}}
onBlur={(event) => {
if (!event.currentTarget.contains(event.relatedTarget as Node | null)) {
setOpen(false);
}
}}
>
<button ref={toggleRef} type="button" aria-expanded={open} aria-controls="lang-menu" onClick={() => setOpen(!open)}>
<span className="visually-hidden">Language:</span> {currentName}
</button>
<ul id="lang-menu" hidden={!open}>
{languages.map((language) => (
<li key={language.code}>
<a href={language.href} hrefLang={language.code} lang={language.code} aria-current={language.code === current ? 'page' : undefined}>
{language.name}
</a>
</li>
))}
</ul>
</nav>
);
}
Pass the URLs of the equivalent pages from the parent Server Component. Use <a> or the Link component, never an onClick that calls router.push on a non-focusable element.
Common mistakes
- Opening the list on hover only: unreachable with the keyboard and on touch screens.
- A
<select>that navigates on change: the first arrow key press changes page. menuandmenuitemroles on navigation links: the screen reader announces an application menu and expects arrow key navigation.- Flag or globe with no accessible name: the screen reader announces "button" or "link" and nothing more.
outline: nonewith no replacement style: the visitor no longer knows where the focus is.- Focus hidden by the sticky header or by a consent pop-up.
- List still open after focus has left: it covers the content and gets in the way of reading.
- Testing only the header on a large screen: the mobile menu switcher and the footer switcher are often different components.
Frequently asked questions
Is a select dropdown accessible for switching language?
The select can be used with the keyboard, but it becomes a problem if it changes page as soon as its value changes: depending on the browser, a single arrow key press is enough to trigger navigation, which fails WCAG success criterion 3.2.2. In that case, add a confirm button, or prefer a list of links shown by a disclosure button, which is simpler to use and crawlable by crawlers.
Which keys must work in a language switcher?
Tab and Shift + Tab to reach the button and each language, Enter or Space to open and close the list, Enter to follow a language's link, Escape to close the list and return to the button. Arrow keys are optional in the W3C disclosure pattern. No key should trap the focus, and the focus outline must stay visible at every step.
How do you tell screen readers which language is current?
Add aria-current="page" to the link of the language being displayed, and put the current language in the button's label, for example "Language: English". Write each language's name in that language and add the lang attribute to its link: the screen reader then pronounces "Deutsch" with the German voice. A flag alone is not enough, because it has no accessible name.
Does the switcher's keyboard accessibility affect SEO?
Not directly: keyboard accessibility is not a ranking factor. But an accessible switcher relies on real named links, present in the HTML, which crawlers follow to discover the language versions and which AI agents can use. Accessibility and crawlability fixes therefore point the same way, and benefit visitors first.
Resources
- W3C APG: Disclosure pattern and disclosure navigation examplew3.org
- W3C: WCAG 2.2 and Understanding success criterion 3.2.2w3.org
- W3C: Technique SCR19, select without a change of contextw3.org
- W3C: Using select to link to localized contentw3.org
- RGAA: official French accessibility frameworkaccessibilite.numerique.gouv.fr
- MDN: :focus-visible pseudo-classdeveloper.mozilla.org
- Polylang: The language switcherpolylang.pro
Updated on
Topic checklist (PDF)