CSS OTP Code Input
Boxed one-time-code inputs for verification and two-factor screens.
HTML
<div class="otp">
<input type="text" inputmode="numeric" maxlength="1" value="4" aria-label="Digit 1">
<input type="text" inputmode="numeric" maxlength="1" value="2" aria-label="Digit 2">
<input type="text" inputmode="numeric" maxlength="1" aria-label="Digit 3">
<input type="text" inputmode="numeric" maxlength="1" aria-label="Digit 4">
</div>
CSS
.otp {
display: flex;
gap: 10px;
}
.otp input {
box-sizing: border-box;
width: 46px;
height: 56px;
border: 1.5px solid #d1d5db;
border-radius: 12px;
background: #fff;
color: #111;
caret-color: #6366f1;
font: 700 22px system-ui, sans-serif;
text-align: center;
outline: none;
transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.otp input:focus {
border-color: #6366f1;
box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.15);
}
About this CSS OTP Code Input
This CSS OTP Code Input is 24 lines of pure CSS (0.5 KB) with no JavaScript and no dependencies. It uses transitions, box shadows and Flexbox. It works in current versions of Chrome, Edge, Safari and Firefox. It works in any stack: plain HTML, React, Vue, Svelte, Astro, WordPress or Webflow.
CSS features used
Customize it
The colors in this snippet. Search and replace them to match your brand:
#d1d5db#fff#111#6366f1
How to use this otp code input
- Copy the HTML and paste it where you want the element to appear.
- Copy the CSS into your stylesheet, or inside a
<style>tag. - Keep the
.otpclass name, or rename it in both places. Then tweak colors, sizes and timing to match your design. - Using React or Next.js? Change
classtoclassNamein the HTML. The CSS works as is, including in Tailwind projects (put it in your global stylesheet).
Building with an AI tool?
“Copy for AI” copies a short prompt for Cursor, Claude Code, Lovable, Bolt or v0. Your AI tool opens the Markdown version of this snippet and reads the HTML, CSS and setup notes there. If your tool can't open links, with the code instead. More ways to use copy CSS with AI.