10.2k

OTP Field

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

API Reference

This component wraps Base UI OTP Field.

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 OTPField.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 OTPField.Input). Slots are ordered by DOM order in the tree (no index prop).

Label the OTP control on the root (OTPField) with aria-label or a visible <label>/FieldLabel. In Base UI 1.6+, the first OTPFieldInput should inherit that field label, while subsequent slots can use aria-label (for example, Character 2 of 6).

OTPFieldSeparator

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

Examples

Large

With Separator

With Label

Custom normalization

Set validationType="none" with normalizeValue 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 normalization.

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