Bootstrap 5 Email Verification Code Form (OTP Input)
An email verification screen with six single-digit code boxes that auto-advance, support paste and backspace navigation, and validate on submit. A resend link is disabled behind a short countdown.
<section class="wdw-stage">
<div class="container" style="max-width: 600px">
<form class="wdw-card p-4 p-md-5 text-center" id="otpForm" novalidate>
<div class="text-start mb-3">
<a href="#" class="small fw-semibold text-decoration-none d-inline-flex align-items-center gap-1">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M15 6l-6 6 6 6"/></svg>
Change email
</a>
</div>
<span class="wdw-icon mx-auto mb-3" style="width:3.5rem;height:3.5rem;border-radius:1.1rem">
<svg width="26" height="26" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="3" y="5" width="18" height="14" rx="3"/><path d="M3.5 7l8.5 6 8.5-6"/></svg>
</span>
<h1 class="h3 wdw-heading mb-2">Verify your email</h1>
<p class="wdw-muted mb-4">We sent a 6-digit code to <strong class="text-body-emphasis">[email protected]</strong>. Enter it below to finish signing up.</p>
<fieldset class="mb-2">
<legend class="visually-hidden">Verification code</legend>
<div class="d-flex justify-content-center gap-2 gap-sm-3 otp-row" id="otpRow">
<input class="form-control otp-box is-filled" inputmode="numeric" maxlength="1" autocomplete="one-time-code" aria-label="Digit 1" value="4">
<input class="form-control otp-box is-filled" inputmode="numeric" maxlength="1" aria-label="Digit 2" value="8">
<input class="form-control otp-box is-filled" inputmode="numeric" maxlength="1" aria-label="Digit 3" value="2">
<input class="form-control otp-box is-filled" inputmode="numeric" maxlength="1" aria-label="Digit 4" value="9">
<input class="form-control otp-box is-next" inputmode="numeric" maxlength="1" aria-label="Digit 5">
<input class="form-control otp-box" inputmode="numeric" maxlength="1" aria-label="Digit 6">
</div>
</fieldset>
<p class="small mb-3 text-danger-emphasis" id="otpMsg" role="status" aria-live="polite" style="min-height:1.25rem"></p>
<button type="submit" class="btn btn-primary rounded-pill w-100" id="otpSubmit">Verify email</button>
<p class="small wdw-muted mt-4 mb-0">
<span id="otpTimer">Resend code in 0:30</span>
<button type="button" class="btn btn-link p-0 align-baseline small fw-semibold text-decoration-none" id="otpResend" hidden style="min-height:0">Resend code</button>
</p>
</form>
</div>
</section>
/* Web Designer Wall library style — shared base for every Bootstrap 5 snippet.
Indigo accent, Plus Jakarta Sans, soft cards, pill buttons. Works in light and dark. */
@import url("https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700;800&display=swap");
:root,
[data-bs-theme="light"] {
--wdw-font: "Plus Jakarta Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
--bs-body-font-family: var(--wdw-font);
--bs-primary: #4f46e5;
--bs-primary-rgb: 79, 70, 229;
--bs-primary-text-emphasis: #3730a3;
--bs-primary-bg-subtle: #eef2ff;
--bs-primary-border-subtle: #c7d2fe;
--bs-link-color: #4f46e5;
--bs-link-color-rgb: 79, 70, 229;
--bs-link-hover-color: #4338ca;
--bs-link-hover-color-rgb: 67, 56, 202;
--bs-focus-ring-color: rgba(79, 70, 229, 0.25);
--bs-border-radius: 0.75rem;
--bs-border-radius-lg: 1rem;
--bs-border-radius-xl: 1.25rem;
--wdw-radius-card: 1.25rem;
--wdw-shadow: 0 1px 2px rgba(16, 24, 40, 0.05), 0 16px 40px -16px rgba(16, 24, 40, 0.22);
--wdw-shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06), 0 4px 12px -4px rgba(16, 24, 40, 0.12);
--wdw-stage: #f5f6fb;
}
[data-bs-theme="dark"] {
--bs-primary: #818cf8;
--bs-primary-rgb: 129, 140, 248;
--bs-primary-text-emphasis: #c7d2fe;
--bs-primary-bg-subtle: rgba(129, 140, 248, 0.14);
--bs-primary-border-subtle: rgba(129, 140, 248, 0.35);
--bs-link-color: #a5b4fc;
--bs-link-color-rgb: 165, 180, 252;
--bs-link-hover-color: #c7d2fe;
--bs-link-hover-color-rgb: 199, 210, 254;
--bs-focus-ring-color: rgba(129, 140, 248, 0.35);
--wdw-shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 16px 40px -16px rgba(0, 0, 0, 0.7);
--wdw-shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4), 0 4px 12px -4px rgba(0, 0, 0, 0.5);
--wdw-stage: #0f1117;
}
body { font-family: var(--wdw-font); -webkit-font-smoothing: antialiased; }
/* Bootstrap compiles its blue into these components; point them at the accent. */
.btn-primary {
--bs-btn-bg: var(--bs-primary); --bs-btn-border-color: var(--bs-primary);
--bs-btn-hover-bg: #4338ca; --bs-btn-hover-border-color: #4338ca;
--bs-btn-active-bg: #3730a3; --bs-btn-active-border-color: #3730a3;
--bs-btn-disabled-bg: var(--bs-primary); --bs-btn-disabled-border-color: var(--bs-primary);
--bs-btn-focus-shadow-rgb: var(--bs-primary-rgb);
}
[data-bs-theme="dark"] .btn-primary { --bs-btn-color: #0f1117; --bs-btn-hover-bg: #a5b4fc; --bs-btn-hover-border-color: #a5b4fc; --bs-btn-hover-color: #0f1117; --bs-btn-active-color: #0f1117; }
.btn-outline-primary {
--bs-btn-color: var(--bs-primary); --bs-btn-border-color: var(--bs-primary);
--bs-btn-hover-bg: var(--bs-primary); --bs-btn-hover-border-color: var(--bs-primary);
--bs-btn-active-bg: var(--bs-primary); --bs-btn-active-border-color: var(--bs-primary);
--bs-btn-focus-shadow-rgb: var(--bs-primary-rgb);
}
.btn { --bs-btn-font-weight: 600; min-height: 44px; display: inline-flex; align-items: center; justify-content: center; gap: .5rem; }
.btn-sm { min-height: 36px; }
.form-control, .form-select { min-height: 44px; border-radius: .75rem; }
.form-control:focus, .form-select:focus, .form-check-input:focus { border-color: rgba(var(--bs-primary-rgb), .6); box-shadow: 0 0 0 .25rem var(--bs-focus-ring-color); }
.form-check-input:checked { background-color: var(--bs-primary); border-color: var(--bs-primary); }
.nav-pills { --bs-nav-pills-link-active-bg: var(--bs-primary); }
.nav { --bs-nav-link-color: var(--bs-secondary-color); --bs-nav-link-hover-color: var(--bs-emphasis-color); }
.pagination { --bs-pagination-active-bg: var(--bs-primary); --bs-pagination-active-border-color: var(--bs-primary); --bs-pagination-color: var(--bs-body-color); --bs-pagination-focus-box-shadow: 0 0 0 .25rem var(--bs-focus-ring-color); }
.progress, .progress-stacked { --bs-progress-bar-bg: var(--bs-primary); }
.list-group { --bs-list-group-active-bg: var(--bs-primary); --bs-list-group-active-border-color: var(--bs-primary); }
.dropdown-menu { --bs-dropdown-link-active-bg: var(--bs-primary); border-radius: .875rem; box-shadow: var(--wdw-shadow-sm); }
.accordion { --bs-accordion-active-bg: var(--bs-primary-bg-subtle); --bs-accordion-active-color: var(--bs-primary-text-emphasis); --bs-accordion-btn-focus-box-shadow: 0 0 0 .25rem var(--bs-focus-ring-color); }
.badge { font-weight: 600; }
/* Library building blocks — use these instead of re-inventing them per snippet. */
.wdw-stage { min-height: 100vh; display: flex; align-items: center; background: var(--wdw-stage); padding-block: 3rem; }
.wdw-card { background: var(--bs-body-bg); border: 1px solid var(--bs-border-color-translucent); border-radius: var(--wdw-radius-card); box-shadow: var(--wdw-shadow); }
.wdw-card-sm { background: var(--bs-body-bg); border: 1px solid var(--bs-border-color-translucent); border-radius: 1rem; box-shadow: var(--wdw-shadow-sm); }
.wdw-aurora { position: relative; color: #fff; background: radial-gradient(60% 55% at 100% 0, #818cf8 0, transparent 70%), radial-gradient(65% 60% at 0 100%, #ec4899 0, transparent 65%), #1e1b4b; }
.wdw-eyebrow { display: inline-block; font-size: .75rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--bs-primary); }
.wdw-heading { font-weight: 800; letter-spacing: -.02em; color: var(--bs-emphasis-color); }
.wdw-muted { color: var(--bs-secondary-color); }
.wdw-icon { width: 2.75rem; height: 2.75rem; flex: none; display: inline-flex; align-items: center; justify-content: center; border-radius: .875rem; background: var(--bs-primary-bg-subtle); color: var(--bs-primary); }
/* Component */
.otp-box { width: 4.25rem; height: 4.75rem; border: 2px solid var(--bs-border-color); background: var(--bs-tertiary-bg); padding: 0; text-align: center; font-size: 1.75rem; font-weight: 700; border-radius: 1rem; }
.otp-box.is-filled { border-color: var(--bs-primary); background: var(--bs-primary-bg-subtle); }
.otp-box.is-next, .otp-box:focus { border-color: var(--bs-primary); background: var(--bs-body-bg); box-shadow: 0 0 0 .25rem rgba(var(--bs-primary-rgb), .25); }
.otp-row.shake { animation: otp-shake .4s; }
@keyframes otp-shake { 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }
@media (max-width: 520px) { .otp-box { width: 2.75rem; height: 3.5rem; font-size: 1.4rem; border-radius: .75rem; } .otp-row { gap: .4rem !important; } }
function initOtp() {
const form = document.getElementById('otpForm');
if (!form) return;
const boxes = [...form.querySelectorAll('.otp-box')];
const row = document.getElementById('otpRow');
const msg = document.getElementById('otpMsg');
const resend = document.getElementById('otpResend');
const timer = document.getElementById('otpTimer');
let left = 0, tick;
const sync = (box) => box.classList.toggle('is-filled', !!box.value);
const clearHint = () => boxes.forEach((b) => b.classList.remove('is-next'));
boxes.forEach((box, i) => {
box.addEventListener('input', () => {
box.value = box.value.replace(/\D/g, '').slice(0, 1);
sync(box);
if (box.value && boxes[i + 1]) boxes[i + 1].focus();
});
box.addEventListener('keydown', (e) => {
if (e.key === 'Backspace' && !box.value && boxes[i - 1]) {
e.preventDefault();
boxes[i - 1].value = '';
sync(boxes[i - 1]);
boxes[i - 1].focus();
}
if (e.key === 'ArrowLeft' && boxes[i - 1]) boxes[i - 1].focus();
if (e.key === 'ArrowRight' && boxes[i + 1]) boxes[i + 1].focus();
});
box.addEventListener('focus', () => { clearHint(); box.select(); });
box.addEventListener('paste', (e) => {
e.preventDefault();
const digits = (e.clipboardData.getData('text') || '').replace(/\D/g, '').slice(0, boxes.length);
boxes.forEach((b, k) => { b.value = digits[k] || ''; sync(b); });
(boxes[digits.length] || boxes[boxes.length - 1]).focus();
});
});
form.addEventListener('submit', (e) => {
e.preventDefault();
const code = boxes.map((b) => b.value).join('');
if (code.length < boxes.length) {
msg.className = 'small mb-3 text-danger-emphasis';
msg.textContent = 'Enter all 6 digits of your code.';
row.classList.remove('shake'); void row.offsetWidth; row.classList.add('shake');
return;
}
msg.className = 'small mb-3 text-success-emphasis';
msg.textContent = 'Email verified. Redirecting…';
});
const label = (s) => `Resend code in 0:${String(s).padStart(2, '0')}`;
function startTimer() {
left = 30;
resend.hidden = true; timer.hidden = false;
timer.textContent = label(left);
clearInterval(tick);
tick = setInterval(() => {
left -= 1;
timer.textContent = label(left);
if (left <= 0) { clearInterval(tick); timer.hidden = true; resend.hidden = false; }
}, 1000);
}
resend.addEventListener('click', () => { msg.className = 'small mb-3 text-body-secondary'; msg.textContent = 'A new code is on its way.'; startTimer(); });
startTimer();
}
initOtp();
Built on Bootstrap 5.3.8 with plain JavaScript — no jQuery. Supports light and dark mode via data-bs-theme.