---
agent:
  instructions: "Search goop.so for Goop's components, templates, design skill, docs, pricing and terms. Ask in keywords or a plain question, such as \"date picker props\" or \"is the design skill free\"; the answer is the matching page sections in Markdown, each with its address."
  endpoint: "https://goop.so/.well-known/search?q={query}"
  method: "GET"
  documentation: "https://developers.cloudflare.com/ai-search/how-to/search-for-agents/"
---

# OTP input

A row of single-character cells for a one-time code, for a two-step sign-in or confirming an email or a phone, for React and Tailwind CSS. Part of Goop Pro.

Pro. Its export: `OtpInput`.

## Try it

Type or paste a code: the last character sends it. A wrong code shows the error, clears the field and keeps the focus there; 246810 signs in (K7QD2M9P in the invite's letters look). Backspace, the arrows, Home and End edit it as one field. Look switches two groups of three, one row of six, or eight letters and digits.

The service is a timer that knows one code per look; "Send a new code" sends nothing.

## When to use

- A row of single-character cells for a one-time code, for a two-step sign-in or confirming an email or a phone.
- Also called: one-time code input, verification code or PIN input.

## Installation

Paste the prompt below into your coding agent. It reads Goop's install steps, installs the part and its tokens once, then reuses this same OTP input on every screen instead of drawing a new one: the same height, the same focus ring, the same spacing. As a Pro part, its command comes from Goop's server once you sign in, with a one-time link that lasts ten minutes.

```sh
npx shadcn@4.23.1 add https://registry.goop.so/g/<link>/meadow-otp-input.json --yes
```

```text
Add the Goop OTP input to this project. The install steps are at https://goop.so/docs/install.md
```

## Usage

```tsx
import { useState } from 'react';
import { Button } from '@/components/ui/goop/button';
import { Field } from '@/components/ui/goop/field';
import { FieldInvalid } from '@/components/ui/goop/field-error';
import { OtpInput } from '@/components/ui/goop/otp-input';

function VerifyCode() {
  const [code, setCode] = useState('');
  const [error, setError] = useState('');
  const [field, setField] = useState<HTMLInputElement | null>(null);
  const verify = (entered: string) => {
    if (entered === '424242') return;
    setError('That code is not right. Check the latest message and try again.');
    setCode('');
    field?.focus();
  };
  return (
    <form
      noValidate
      className="flex flex-col gap-4"
      onSubmit={(event) => {
        event.preventDefault();
        verify(code);
      }}
    >
      <Field label="Verification code" orientation="vertical">
        <FieldInvalid error={error}>
          <OtpInput
            ref={setField}
            name="code"
            groups={[3, 3]}
            value={code}
            onValueChange={(next) => {
              setCode(next);
              setError('');
            }}
            onComplete={verify}
          />
        </FieldInvalid>
      </Field>
      <Button type="submit">Verify</Button>
    </form>
  );
}
```

- Fits: account: field.
- Also known as: InputOTP, PinInput, OneTimeCode, VerificationCode, DigitInput.
- Put an OtpInput in a vertical Field and a FieldInvalid on a sign-in or confirmation card; submit from onComplete, and on a wrong code show the error, clear the code and keep the focus in it.
- height, width, padding, gap, corner, border, background, text: add no class for these.

## API reference

### Options

- `length?: number = 6` — How many characters the code has, one cell each.
- `value?: string` — The code, controlled: `''` for an empty field.
- `defaultValue?: string` — The code at first, uncontrolled (empty if left out).
- `onValueChange?: (code: string) => void` — Called with the code each time it changes.
- `onComplete?: (code: string) => void` — Called once with the code when its last cell fills.
- `characters?: 'digits' | 'letters-digits' = 'digits'` — `"digits"` takes 0–9 (a phone's number keypad); `"letters-digits"` letters, upper-cased, and digits.
- `groups?: readonly number[]` — The cells in groups, a dash between them (`[3, 3]`), adding up to `length`.
- `lengthLabel?: string` — The hidden words heard after the field's name; "6 digits" by default.
- `onChange?: (event: ChangeEvent<HTMLInputElement>) => void`
- `name?: string`
- `required?: boolean`
- `disabled?: boolean`
- `form?: string`
- `Defaults: autoComplete = 'one-time-code'`

- State: value (value / defaultValue / onValueChange); drawn by data-invalid

## Keyboard

- 0-9 (A-Z with letters-digits): fill the active cell and move to the next
- Backspace: clear the cell before the caret (the last filled)
- ArrowLeft / ArrowRight: move the caret one cell, never past the next empty one
- Home / End: move the caret to the first cell, or the next empty one
- Enter: submit the form

## Accessibility

- The native element answers the keyboard.
- hover, focus-within: the browser's own (:hover, :focus-within): write nothing
- disabled: the prop disabled
- invalid: the attribute data-invalid

## Notes for AI

Give your coding agent this page as text instead of screenshots: the parts, the options, the states and the keys. An agent that reads the real part builds the real part, not a lookalike.

## Related

- [Button](/themes/meadow/components/button): A button with words that runs an action, in several looks and sizes, on a page, in a row or in a sidebar.
- [Field](/themes/meadow/components/field): A form row that ties one control to its label and its description, as a settings row or a stacked form field.
- [Field error](/themes/meadow/components/field-error): The error line under a form control whose value was refused, saying what to fix, inside the control's Field.
- [Checkbox](/themes/meadow/components/checkbox): A round box a person ticks to mark one thing done or chosen.
