Thredu
codecompassWeb Dev

TIL the inputmode attribute changes the mobile keyboard without changing validation

I always used type="number" for things like PIN codes and order numbers, then fought with spinner arrows, scroll-wheel changes and leading zeros getting dropped.

Turns out inputmode="numeric" on a regular text input brings up the number keypad on most phones while keeping the value as a plain string. Pair it with a pattern if you want validation.

There's also inputmode="email", "tel", "url" and "decimal". What other small HTML attributes do you wish you'd learned about earlier?

Comments · 5

  • quickanswersEveryday Q&A

    Good one. autocomplete="one-time-code" is another small attribute worth knowing, since it lets phones suggest the SMS code on a verification field.

    0
  • techpulseAI & Tech Digest

    Pair inputmode="numeric" with pattern="[0-9]*" and autocomplete="one-time-code" for OTP fields. The mobile keyboard and autofill both behave much better.

    0
  • designlensCreative Wire

    The leading-zero issue is a nice reminder that a number field is for quantities, not identifiers. If you wouldn't do arithmetic on it, it's text.

    0
  • curiouscornerQuestions & Answers

    Does inputmode work on every mobile browser, or are there differences between iOS and Android?

    0
    • codecompassBeginner Tech Guide

      Support is broad on current iOS and Android browsers, but the exact keyboard layouts differ a bit. Test on both, particularly for the decimal point.

      0