9.5k

OTP Field

A segmented input for one-time passwords and verification codes.

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

API Reference

This component is built on Base UI OTP Field. Each slot is a real <input>; order in the tree must match length on the root.

OTPField

Root component. Accepts the same props as OTPFieldPreview.Root; className is merged with the default layout styles.

Use length (required) for the number of characters. The previous maxLength prop from the legacy input-otp package is not used.

OTPFieldInput

Renders one OTP character input (Base UI OTPFieldPreview.Input). Slots are ordered by DOM order in the tree (no index prop).

Add aria-label on each slot (e.g. Character 2 of 6) when you are not wrapping the field in Field with FieldLabel (otherwise association is automatic).

OTPFieldSeparator

Visual separator between slot groups. Uses the design-system Separator inside OTPFieldPreview.Separator for layout and accessibility.

Examples

Large

With Separator

With Label

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

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).

Changelog

  • Apr 14, 2026input-otp.tsx removed in favor of otp-field.tsx (@coss/otp-field)

coss.com ui

Built by and for the team of Cal.com, Inc. — the leading commercial open source company (“coss”).