---
title: "OTP Input | Free React & Tailwind Blocks Component | Motion UI"
canonical: "https://blacknest.dev/motion/c/blocks/otp-input"
github_source: "https://github.com/Rkj0123/motion-ui-skill/blob/main/components/motion/otp-input.tsx"
install_command: "npx motion-ui-skill add otp-input"
dependencies: ["clsx","motion","react","tailwind-merge"]
category: "blocks"
subcategory: "motion"
---

# OTP Input

> One-time-code input with a gliding focus ring, digits that roll in per slot, error shake and a success check draw.

## Install

```bash
npx motion-ui-skill add otp-input
```

## Dependencies

- `clsx`
- `motion`
- `react`
- `tailwind-merge`

## Usage

```tsx
"use client";

import { useState } from "react";
import { OTPInput, type OTPStatus } from "@/components/motion/otp-input";

const CODE = "123456";

export function OTPInputPreview() {
  const [value, setValue] = useState("");
  const [status, setStatus] = useState<OTPStatus>("idle");

  return (
    <div className="flex flex-col items-center gap-4">
      <OTPInput
        label="Verification code"
        hint={`Enter ${CODE} to verify.`}
        successMessage="Verified."
        errorMessage="Wrong code, try again."
        value={value}
        status={status}
        onChange={(v) => {
          setValue(v);
          if (status !== "idle") setStatus("idle");
        }}
        onComplete={(v) => setStatus(v === CODE ? "success" : "error")}
      />
    </div>
  );
}
```

## API Reference

### OTPInput

| Prop | Type | Default | Required | Description |
| --- | --- | --- | --- | --- |
| `length` | `number` | `6` | No | Number of slots. Default 6. |
| `value` | `string` | — | No | — |
| `defaultValue` | `string` | — | No | — |
| `onChange` | `((value: string) => void)` | — | No | — |
| `onComplete` | `((value: string) => void)` | — | No | Fires once every slot is filled. |
| `label` | `string` | — | No | Optional label rendered above the slots. |
| `hint` | `string` | — | No | Helper text shown below the slots while idle. |
| `successMessage` | `string` | — | No | Message shown below the slots when status is "success". |
| `errorMessage` | `string` | — | No | Message shown below the slots when status is "error". |
| `status` | `"error" \| "success" \| "idle"` | `idle` | No | External validation feedback. "error" shakes, "success" draws a check. |
| `mask` | `boolean` | `false` | No | Render dots instead of the typed digits. |
| `disabled` | `boolean` | `false` | No | — |
| `autoFocus` | `boolean` | `false` | No | — |
| `aria-label` | `string` | `One-time passcode` | No | Accessible label for the underlying input. |
| `className` | `string` | — | No | — |

## Source Files

- [components/motion/otp-input.tsx](https://github.com/Rkj0123/motion-ui-skill/blob/main/components/motion/otp-input.tsx)
- [lib/ease.ts](https://github.com/Rkj0123/motion-ui-skill/blob/main/lib/ease.ts)
- [lib/utils.ts](https://github.com/Rkj0123/motion-ui-skill/blob/main/lib/utils.ts)
