Vanilla Breeze v0.7.4

Vanilla Breeze v0.7.4 released

0.7.4 gives the Ambient pack weather. A page names one feed URL on its own site, and the pack sets data-weather from it, uses its sunrise and sunset for dawn and dusk, and never shows a stale observation. Helpers for producing the feed from Open-Meteo are included. Ambient p…

Read the release notes

inputmode

Chooses which on-screen keyboard a touch device shows for a field (numeric, decimal, tel, email, url, search or none) without changing the field's type or validation.

Overview

inputmode tells the browser which virtual keyboard to show. It changes nothing else: no validation, no spinners, no value parsing. That makes it the right tool when the data is digits but not a number, such as a PIN, a postal code or a card number, where type="number" would add behaviour you don't want.

Applies to: any editable element: <input>, <textarea> and elements with contenteditable. It is a global attribute, so it is allowed anywhere but only has an effect where text can be entered.

Values

ValueKeyboardUse for
textStandard, in the user's localeThe default for text fields.
numericDigits 0–9PINs, postal codes, one-time codes, card numbers.
decimalDigits and the locale's decimal separatorPrices, measurements.
telPhone keypad with *, # and +Phone numbers in a field that isn't type="tel".
emailText with @ and . to handEmail in a field that isn't type="email".
urlText with / and . to handAddresses in a field that isn't type="url".
searchText, Enter labelled for searchSearch boxes.
noneNo virtual keyboardFields filled by your own on-screen UI (a keypad, a picker). The field still takes focus and a hardware keyboard.
Absent, empty or invalidThe browser picks from the type—

Inherited: no. Each editable element sets its own. type="tel", email, url, number and search already choose a suitable keyboard, so inputmode is mainly for type="text" fields and contenteditable.

Examples

inputmode versus type="number"

type="number" is for quantities you would increment. On codes and identifiers it gets in the way: spin buttons appear, the mouse wheel and arrow keys change the value, letters such as e are accepted (as in 1e5), and long digit strings such as card numbers lose precision as numbers. Use type="text" inputmode="numeric" plus a pattern.

For real quantities, keep type="number"; see min, max and step and the numeric inputs guide.

Editable text outside a form control

In Vanilla Breeze

  • data-mask sets inputmode="numeric" when the mask is digits only (phone, credit card, ZIP and so on) and the input has no inputmode of its own (src/utils/mask-init.js).
  • data-accept presets set a matching mode when none is given: numeric for digits, date and cc; decimal for currency; tel for phone; text for the other presets and for custom character classes (src/utils/accept-init.js).
  • OTP fields. <form-field> with input[data-type="otp"] or [data-type="pin"] gives each digit box inputmode="numeric" (src/lib/form-field-enhancements.js).
  • An author inputmode always wins; VB only fills it in when it's missing.

Accessibility

  • The right keyboard saves effort for everyone on a phone, and particularly for people with motor impairments.
  • Don't use inputmode="none" on a field users must type into. Without your custom keypad, a touch user has no way to enter text.
  • inputmode is a hint, not a restriction. A user with a hardware keyboard, or a keyboard app that ignores the hint, can type anything. Validate with pattern or type.

Browser support

Baseline 2021: Chrome 66, Firefox 95, Safari 12.1. The attribute only affects virtual keyboards, so desktop browsers with a physical keyboard show no change; keyboard apps on Android can ignore it.

Gotchas

  • numeric keyboards on some phones have no minus sign or decimal point. Use decimal, or text, when those are needed.
  • inputmode does not stop invalid characters. Pair it with pattern, or filter keystrokes with data-accept.
  • On type="number" the browser already shows a numeric keyboard; adding inputmode doesn't remove the number behaviours listed above.

Related

Which to choose

  • type="number" — a quantity that can be stepped (guests, age).
  • inputmode="numeric" + pattern — digits that are an identifier (PIN, ZIP, card).
  • data-mask — digits with a visible format; it adds the keyboard for you.
  • data-accept — a free format with a limited character set; it also adds the keyboard.
↑