โœฆ StealThis .dev

OTP / PIN Input

One-time password input with individual digit boxes, auto-advance on type, paste support, backspace to go back, and length variants (4 and 6 digits).

Open in Lab
css vanilla-js
Targets: JS HTML React Native

Expo Snack

Code

OTP / PIN Input

Individual digit input boxes with auto-advance, backspace navigation, and paste support. Four variants cover the most common verification UX patterns.

Variants

  • 6-digit OTP โ€” default verification code input
  • 4-digit PIN โ€” shorter PIN entry
  • 6-digit error โ€” red-bordered invalid state with error message
  • 6-digit success โ€” green-bordered confirmed state

How it works

  1. Each box is an <input maxlength="1" inputmode="numeric"> in a flex row
  2. On a valid digit keypress, the value is set and focus moves to the next box
  3. On Backspace, if the current box is empty, focus moves to the previous box
  4. On paste, the pasted string is split across boxes left-to-right; excess characters are ignored
  5. When the last digit is filled, the group dispatches a complete event with the full code value

States

  • Default โ€” neutral border, accent focus ring
  • Error โ€” red border on all boxes, shake animation, error label below
  • Success โ€” green border on all boxes, checkmark label below