Configuring locale override for HTML5 <input type=date> picker
0 reputation · 23 Jul 2023, 19:56 UTC
0 reputation · 23 Jul 2023, 19:56 UTC
The goal is to make the date picker shown by an element display a specific language or format (for example, the ISO‑8601 pattern) independent of the user's system locale or the page's lang attribute. Currently, browsers derive the picker UI from the operating system locale and ignore the lang attribute, while the submitted value is always the canonical 'YYYY‑MM‑DD' string. This creates a mismatch between what users see and what the application receives, and there is no standard HTML attribute or CSS property to override the picker's locale.
Is there a way to force the picker UI to adopt a chosen locale without breaking its native accessibility features? Can a JavaScript polyfill safely replace the picker while preserving keyboard navigation and ARIA roles? Does the HTML5 specification provide any extension point or future attribute that would allow developers to specify the picker's locale explicitly?
34775 reputation · 24 Jul 2023, 05:49 UTC
There is no HTML attribute that can reliably change the language or format shown by the native <input type="date"> picker. Browsers derive the UI from the operating‑system locale or the Accept‑Language header, and most ignore the lang attribute on the element or the page. If you need a guaranteed, language‑consistent UI, the only practical path is to replace the native picker with a JavaScript date‑picker library that exposes a locale configuration.
lang on the <input> in a predictable way.lang works, the format is still tied to the OS locale, not the attribute, so the value submitted remains the canonical YYYY‑MM‑DD.lang trick first:
<input type="date" lang="fr">
Check the picker; if it still shows the default locale, fall back to a polyfill.import flatpickr from "flatpickr";
import "flatpickr/dist/l10n/fr.js";
flatpickr("#date", { locale: "fr" });
These maintain keyboard navigation and ARIA roles when initialized with the altInput option.role="textbox" and aria-label attributes, and that screen‑reader announcements match the displayed format.<input type="date"> as a graceful degradation fallback; it will still submit the ISO string.If you are targeting a specific set of browsers or devices, let me know which ones. That will narrow the recommendation to a more precise workaround.
Use comments to ask for clarification. Post a solution as an answer.
34,775 reputation · 23 Jul 2023, 22:46 UTC
When a JavaScript date picker overlays the native control—such as Flatpickr’s altInput pattern—the original <input type="date"> typically stays in the DOM to hold the canonical YYYY-MM-DD value. In that setup, min, max, and step still constrain the hidden field, not the localized string users see. Server-side validation should therefore target the canonical field; checking the display format will reject valid dates.
One practical check: ensure that hidden input is not marked disabled, because disabled controls are excluded from form submission.