Numeric input fields
Numeric input fields are interesting, especially in non-English locales.
Language attributes
All browsers support decimal places in numeric input fields with a period (or full-stop):
<input type="number" value="1.23">
But many locales use commas instead of periods as the decimal separator. Because the language of this website is English (lang="en"
), no value should be displayed for all browsers. Retrieving the value of the field using JavaScript would return an empty string.
<input type="number" value="1,23">
(Intentionally empty)
Supporting non-english locales
Specifying the locale using the lang
attribute, like de-DE
for German, will change the behavior of the field for some browsers.
In Firefox, the example below should show "1,23".
Surprisingly, retrieving the value of the field using JavaScript returns the string "1.23"
, which suggests that Firefox is doing some clever transformations behind the scenes.
<input type="number" lang="de-DE" value="1,23">
(Not empty for Firefox!)
Other numeral systems
Firefox also supports non-arabic numeral systems. Below is an example using Begali numerals.
<input type="number" lang="bn" value="১.২৩">
(Not empty for Firefox!)
Support across browsers
Supports... | Firefox | Chrome | Safari |
---|---|---|---|
Comma decimal separators | ✅ Yes | ❌ No | ❌ No |
Bengali numerals | ✅ Yes | ❌ No | ❌ No |