OTP Field

A one-time code with a box for each character.

Enter the 6-digit code we sent to ada@example.com.

Installation

  1. Add the registryOnce per project
  2. Add otp-field

Usage

Render one OTPFieldInput per character, matching length. An id on OTPField goes to the first box, so a label can point at it.

Composition

Examples

Checking the code

onValueComplete runs once every box is filled. Set invalid on the Field and aria-invalid on the inputs, and show a FieldError when the code is wrong.

Try 424242, or any other code to see an error.

Groups

Split a long code into OTPFieldGroups with an OTPFieldSeparator between them.

Large

Letters and numbers

The field accepts only digits by default. Set validationType="alphanumeric" to allow letters, and normalizeValue to transform input, such as to uppercase.

Letters are converted to uppercase.

Masked

mask hides the characters, like a password field.

Disabled

Props

The tables leave out className, style and render. Parts built on Base UI take them as its styling and composition guides describe.

OTPField

OTPFieldSeparator