ui

OTP Field

A segmented input for one-time passwords and verification codes. Built with Base UI and Tailwind CSS. Copy-paste ready.

API Reference

Note: This component wraps Base UI OTP Field (OTPFieldPreview), which is currently in preview and may change before it becomes stable.

Installation

Usage

Examples

Large

Renders the OTP field with larger slot dimensions for touch-friendly or visually prominent verification UIs.

With Separator

Adds an OTPFieldSeparator between groups of input slots to visually split a code into segments (e.g. 3+3 or 4+4).

With Label

Associates a Label with the OTP field for accessible identification without requiring a Field wrapper.

Custom sanitization

Set validationType="none" with sanitizeValue when you need to normalize pasted input before it reaches state, or to enforce custom character rules. Use inputMode for the virtual keyboard hint, and onValueInvalid when you want to react to characters that were rejected after sanitization.

Auto Validation

Automatically validates and submits the code when all slots are filled, without requiring the user to press a button.

Alphanumeric

Use validationType="alphanumeric" for recovery, backup, or invite codes that mix letters and numbers.

Placeholder hints

Each slot is a real <input>, so placeholder and CSS behave as usual. Hide the placeholder on focus when the active slot should not show a hint.

Masked entry

Pass mask on the root when the code should be obscured while it is typed (e.g. shared screens).

Email Verification Card

A bordered card with a mail icon header, recipient email display, the OTP slots, and an inline "Resend code" button — ready to drop into an email verification flow.

2FA Authenticator App

A compact card with an authenticator app icon, contextual description, OTP input with inputMode="numeric", and a "Verify" submit button.

8-Character Invite Code

A two-group XXXX-XXXX layout using OTPFieldSeparator with validationType="alphanumeric" — suitable for invite, license, or access codes.

Success State

A controlled field that swaps the OTP slots for a green "Identity verified" confirmation once the correct code is entered, and shows a FieldError for wrong attempts.

Resend Countdown Timer

A useEffect-driven countdown shows "Resend code in Xs" while the timer runs, then reveals a clickable "Resend code" link that resets the clock.