Easeout LabOTP Input

OTP Input

A pill that opens into code slots, verifies, and shakes and clears on a wrong code. Paste and SMS autofill work. Try 123456.

Install

npx shadcn add@easeout/otp-input

Dependencies

motiontailwindcss

Tags

InputsFree componentMIT

Usage

After installing, it lives at components/otp-input.tsx

app/example.tsx
"use client"

import { OtpInput } from "@/components/otp-input"

export default function Example() {
  return (
    <OtpInput
      onVerify={async (code) => {
        const res = await fetch("/api/verify", { method: "POST", body: JSON.stringify({ code }) })
        return res.ok
      }}
      onSuccess={() => window.location.assign("/dashboard")}
    />
  )
}

Props

PropTypeDefaultWhat it does
lengthnumber6Number of digits.
onVerify(code: string) => boolean | Promise<boolean>code === "123456"Return true when the code is right. Can be async.
onSuccess(code: string) => void–Called after the success state has shown.
labelstring"One-time code, 6 digits"Accessible name of the input.
cta, verifying, verified, wrongstring–The pill's copy in each state, and the error message.
soundbooleantrueSoft key clicks, a knock on a wrong code and a chime on the right one.
autoplaybooleanfalsePlays a wrong code, then the right one, until someone points at it or focuses it.
classNamestring–Classes for the wrapper.

Want a whole page built like this?