brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: the HTML inputmode attribute picks the right keyboard on phones

Html
~/tips/tip-html-inputmode-mobile-keyboard

cat ~/tips/tip-html-inputmode-mobile-keyboard.md

Hints which virtual keyboard a phone should show for a field, without changing validation.

A text field for a postcode or a price should show a number pad on a phone, not the full keyboard. inputmode is the hint for that.

<input type="text" inputmode="numeric" pattern="[0-9]*" name="pin">
<input type="text" inputmode="decimal" name="price">

The values listed on MDN are none, text (the default), decimal, numeric, tel, search, email and url. numeric asks for digits 0 to 9 only, while decimal adds the decimal separator of the user’s locale, which matters in the Netherlands where that is a comma.

MDN marks the attribute as widely available, working across browsers since December 2021.

The caveat is that inputmode only changes the keyboard. It does not validate anything, and the user can still type letters if the device offers them. Devices also treat it as a hint, so a minus key may or may not appear with numeric or decimal.

When a field really requires a telephone number, email address, URL or search query, MDN says to use the matching type (tel, email, url, search) instead. Type controls validation and meaning, inputmode is for fine tuning. Use type="text" with inputmode="numeric" when you want a number pad but cannot use type="number", for example for codes with leading zeros.

Further reading: MDN: inputmode

More Html tips import { format } from "dates"; width="640" height="360" poster="demo.jpg"> The HTML optgroup element puts headings inside a long dropdown srclang="en" label="English" default> An HTML noindex meta tag keeps one page out of search results All Html tips (14) All topics

Link