---
title: "Input OTP"
description: "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."
url: https://gelatinui.com/components/input-otp
markdown_url: https://gelatinui.com/components/input-otp.md
access: free
install: "npx shadcn@latest add @gelatin-ui/input-otp"
registry_item: https://gelatinui.com/r/input-otp.json
version: "2026-11-08"
index: https://gelatinui.com/llms.txt
docs_index: https://gelatinui.com/docs/llms.txt
---

# Input OTP

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

Page: https://gelatinui.com/components/input-otp

## When to use it

Best for: A one-time code of a fixed length, from 4 to 8 characters, with paste and SMS autofill.

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

## When not to use it

- For a password or a code of no fixed length, use an [Input](https://gelatinui.com/components/input.md).

## Notes for agents

- It takes digits only by default; set `validationType` to `alphanumeric` or `alpha` for codes with letters.
- Paste and SMS autofill fill every slot at once.

## Anatomy

```text
InputOTP
├─ InputOTPGroup (0..n)
├─ InputOTPSlot (0..n)
└─ InputOTPSeparator (0..n)
```

## API reference

### InputOTP

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `className` | `string` |  |  |
| `size` | `ControlSizeAtLeastSm` | "default" | The size of every slot: `sm` 28, `default` 32, `lg` 36. |
| `slotLabel` | `function` | characterLabel | The accessible name of each slot after the first, which takes the field label. Default: "Character 2 of 6". Translate it with the page. |

Also takes every prop of Base UI `OtpField.Root`: https://base-ui.com/react/components/otp-field

### InputOTPGroup

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `className` | `string` |  |  |

### InputOTPSlot

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `className` | `string` |  |  |

### InputOTPSeparator

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `className` | `string` |  |  |

Also takes every prop of Base UI `Separator`: https://base-ui.com/react/components/separator

## Styling

| Part | Slot | States | CSS variables | Tokens |
| --- | --- | --- | --- | --- |
| InputOTP | `input-otp` | `data-disabled` |  |  |
| InputOTPGroup | `input-otp-group` | `aria-invalid` | `--radius` |  |
| InputOTPSlot | `input-otp-slot` | `aria-invalid`, `data-disabled` | `--radius` |  |
| InputOTPSeparator | `input-otp-separator` |  |  |  |

## Usage

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

The sample also uses `field`, which this add does not write. One command adds them with this item:

```bash
npx shadcn@latest add @gelatin-ui/input-otp @gelatin-ui/field
```

```tsx title="sign-in-code.tsx"
import { Field, FieldLabel } from "@/components/ui/field";
import { InputOTP, InputOTPGroup, InputOTPSeparator, InputOTPSlot } from "@/components/ui/input-otp";

export function SignInCode({ onSend }: { onSend: (code: string) => void }) {
  return (
    <Field>
      <FieldLabel>Sign-in code</FieldLabel>
      <InputOTP size="lg" length={6} name="code" onValueComplete={onSend}>
        <InputOTPGroup>
          <InputOTPSlot />
          <InputOTPSlot />
          <InputOTPSlot />
        </InputOTPGroup>
        <InputOTPSeparator />
        <InputOTPGroup>
          <InputOTPSlot />
          <InputOTPSlot />
          <InputOTPSlot />
        </InputOTPGroup>
      </InputOTP>
    </Field>
  );
}
```

## Compose

Rules:

- Compose the parts (`compose-parts`): Build each item from its named parts as children, and pass your text and icons in as parts.
- Every state is designed (`every-state`): Give each view of data its loading, empty, and error states: a skeleton in the final layout, an `Empty` with an illustration and one next action, and an error that says what failed and how to retry.

## Add it

```bash
npx shadcn@latest add @gelatin-ui/input-otp
```

It adds 6 registry items: 3 files, 1320 lines, and the npm packages `@base-ui/react`, `clsx`, `tailwind-merge`, `tailwind-variants`.

## For AI agents

- Every item, one file: https://gelatinui.com/llms.txt
- MCP server (`search_items`, `get_item`, `get_install_plan`): https://gelatinui.com/mcp

## Related

- [Input](https://gelatinui.com/components/input.md)
- [Field](https://gelatinui.com/components/field.md)

## Keyboard

| Keys | Action |
| --- | --- |
| ← | Moves to the slot before. |
| → | Moves to the slot after. |
| Home | Moves to the first slot. |
| End | Moves to the first empty slot, or the last slot. |
| Backspace | Deletes a character and moves to the slot before. |
| Delete | Deletes the character in the slot. |
| Ctrl Backspace | Clears the code (⌘ Backspace on a Mac). |

## Accessibility

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.
