A dark verification screen built on the new Bootstrap 6 OtpInput component. Six digit slots split into two groups, with paste support, auto-advance, automatic verification when the last digit is entered, an error state and a resend countdown. Use it for two-factor login, phone confirmation or email codes.
How it works
The root .ocv-root (with data-bs-theme="dark") centers an .ocv-card. The code field is a single <input> inside <div class="otp otp-lg ocv-otp" data-bs-otp>. Bootstrap reads maxlength="6", hides the real input and draws six .otp-slot boxes. data-bs-groups="[3,3]" adds a separator in the middle. Because it stays one text field, typing moves to the next slot automatically. Backspace, arrow keys and SMS autofill (autocomplete="one-time-code") work, and pasting "246-810" strips the dash.
script.js gets the instance with OtpInput.getOrCreateInstance(). It listens to two Bootstrap events. input.bs.otpInput clears the error and enables the Verify button once all slots are filled. complete.bs.otpInput calls verify(), which shows a spinner and compares the value with DEMO_CODE. A wrong code adds .is-invalid to the .otp wrapper, which colors the slots red and shows the .ocv-error message. A correct code swaps the form for the .ocv-success panel.
"Paste code" reads the clipboard with otp.setValue() and falls back to a hint when clipboard access is blocked. "Clear" calls otp.clear(). The resend link stays hidden until the RESEND_SECONDS countdown in .ocv-timer reaches zero. The demo starts with three digits filled in.
Customization
DEMO_CODEandverify()inscript.js: replace the local comparison with afetch()to your server.RESEND_SECONDSinscript.js: change how long the visitor waits before requesting a new code.maxlengthon the input anddata-bs-groupson.ocv-otp: usemaxlength="4"without groups for a PIN.data-bs-separatorsets the divider character.- Add
data-bs-type="alphanumeric"to.ocv-otpfor letter codes, ordata-bs-mask="true"to show dots. --bs-otp-size,--bs-otp-gapand--bs-otp-slot-border-radiuson.ocv-otp: resize and reshape the slots. Addotp-connectedfor joined boxes.--ocv-amberon.ocv-root: changes the accent, the Verify button (via the scoped--bs-warning-*tokens) and the focus rings.- Remove
value="246"from the input for an empty first state.
Use cases
- Two-factor login: six digit slots auto-advance and verify as soon as the last digit is entered
- Phone number confirmation: SMS autofill and paste support make entering a texted code quick
- Email verification screens: an error state and resend countdown handle wrong or expired codes
- Banking and secure checkout: grouped slots with a clear error message confirm a user's identity
Accessibility
Screen readers announce one labelled text field, not six. The slots are aria-hidden, and help and error text are linked with aria-describedby. Errors set aria-invalid and are announced through a role="status" live region, and the success panel receives focus. Paste and autofill are never blocked, as WCAG 3.3.8 requires. The blinking caret stops under prefers-reduced-motion.
Bootstrap 6 notes
Bootstrap 5 had no OTP component. Developers usually built six separate inputs with custom focus-jumping JavaScript. Bootstrap 6's OtpInput (.otp, data-bs-otp, otp-lg, otp-connected) replaces all of that. Buttons use btn-solid theme-warning, and spinner-border-sm is now spinner-sm. Built on Bootstrap 6.0.0-alpha.1, so APIs may still change.