Skip to content

Input OTP

New

A field for a one-time code, one character per slot, in groups. People can paste the code, or the phone fills it from a text message.

  • Base UI
  • React 19
  • Tailwind CSS 4

Added Nov 8, 2026 · MIT + Commons Clause

Playground

Loading the preview

Props

Set length and render that many InputOTPSlots. Put the code in a Field with one FieldLabel: the first slot takes the label.

The sample also uses Field. One command adds them with this item:

sign-in-code.tsx

InputOTP

<div>
PropTypeDefaultDescription
classNamestring—
size"default""lg""sm""default"The size of every slot: sm 28, default 32, lg 36.
slotLabelcharacterLabelThe accessible name of each slot after the first, which takes the field label. Default: "Character 2 of 6". Translate it with the page.
From Base UIOtpField.RootBase UI docs
idstring—The id of the first input element. Subsequent inputs derive their ids from it ({id}-2, {id}-3, and so on).
autoCompletestring'one-time-code'The input autocomplete attribute. Applied to the first slot and hidden validation input.
formstring—A string specifying the form element with which the hidden input is associated. This string's value must match the id of a form element in the same document.
...props<div> attributes—Every other attribute goes to the <div>, with a ref.

InputOTPGroup

<div>
PropTypeDefaultDescription
classNamestring—
...props<div> attributes—Every other attribute goes to the <div>, with a ref.

InputOTPSlot

<div>
PropTypeDefaultDescription
classNamestring—
...props<div> attributes—Every other attribute goes to the <div>, with a ref.

InputOTPSeparator

<div>
PropTypeDefaultDescription
classNamestring—
From Base UISeparatorBase UI docs
orientation"horizontal""vertical"'horizontal'The orientation of the separator.
render—Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a ReactElement or a function that returns the element to render.
style—Style applied to the element, or a function that returns a style object based on the component's state.
...props<div> attributes—Every other attribute goes to the <div>, with a ref.
  • Use it for a short code of a fixed length, from 4 to 8 characters.
  • Group the slots for the eye, such as 3 + 3. Screen readers skip the separator.
  • Set validationType to alphanumeric or alpha for codes with letters. The default takes digits only.
  • Use mask to hide the characters of a secret code.
  • For a password or a code of no fixed length, use an Input.
←Moves to the slot before.
→Moves to the slot after.
HomeMoves to the first slot.
EndMoves to the first empty slot, or the last slot.
BackspaceDeletes a character and moves to the slot before.
DeleteDeletes the character in the slot.
CtrlBackspaceClears the code (⌘ Backspace on a Mac).

Each slot is a Base UI OTPField.Input, a native <input> for one character. The first slot takes the field label. Each later slot gets its own aria-label, such as "Character 2 of 6". Translate it with slotLabel on the root.

Base UI sets autocomplete and maxLength on the first slot only, so SMS autofill and password managers fill the full code. A paste fills all slots.

InputOTPSeparator is hidden from screen readers (aria-hidden): it only groups the characters for the eye.

A numeric code stays left to right on a right-to-left page, and the arrow keys follow the same direction.

  1. AddedInput OTP.
Open the release