Skip to content

OTP Verification Screen with Code Inputs

OTP verification screen with six one-digit code inputs, auto advance, paste and one-time-code autofill, a resend timer and an edit phone number sheet.

Also known as: otp input screen, sms verification code input, one time password ui, phone number verification screen, 2fa code entry

OTP Verification Screen with Code Inputs live demo

Open in new tab

Bootstrap 5 code (HTML, CSS, JS)

An HTML mobile template for an OTP verification screen: six one-digit code inputs with auto advance, paste support and one-time-code autofill, a resend timer and a sheet to edit the phone number. Use this SMS verification code input as the second step of a sign-up or two-factor login in mobile sites and PWAs, or package it with Capacitor. Built with Bootstrap 5 and Bootstrap Icons in a white and teal style.

How it works

The root .otv-app is a centred app column (max 430 px) with a code panel and a success panel ([data-otv-panel]). The .otv-form holds six .otv-digit inputs in a fieldset; the first has autocomplete="one-time-code" and all use inputmode="numeric", so phones show the number pad and offer the SMS code.

Typing a digit moves to the next cell, Backspace in an empty cell clears the previous one, and the arrow keys move between cells. Pasting or autofilling several digits spreads them over the cells. When all six are filled the code is checked automatically; A wrong code shakes the row and shows the remaining attempts; after three, the cells lock until a new code is sent.

The .otv-timer counts down from data-otv-seconds and then shows the Resend button. "Call me instead" switches the text to a voice call and restarts the timer. Edit number and Change number open the Bootstrap offcanvas .otv-sheet, a bottom sheet with a country code select and a type="tel" field (7 to 12 digits).

Customization

  • data-otv-code on .otv-app: the demo code (246810). Remove the .otv-help hint and check the code on your server instead.
  • data-otv-seconds on .otv-app: the resend wait time in seconds.
  • maxAttempts in script.js: how many wrong codes are allowed before the cells lock.
  • --otv-teal, --otv-teal-dark and --otv-teal-soft on .otv-app: the primary colour, its hover shade and the light tint.
  • --otv-cell on .otv-app: the width of each code cell (40 px below 360 px screens).
  • The window.setTimeout in verify(): replace it with a fetch() to your verification endpoint.
  • The options of .otv-cc: add the country codes your service supports.

Use cases

  • Sign-up flows in fintech, delivery and marketplace apps: confirm the phone number before creating the account
  • Two-factor login in banking or health apps: enter the SMS code after the password
  • Ride-hailing and taxi apps: verify the rider's number on first launch

Accessibility

Each cell has an aria-label such as "Digit 3 of 6" inside a fieldset with a hidden legend. Errors appear in a role="alert" paragraph and are linked to the first cell with aria-describedby, and the cells get aria-invalid. Resend, voice call and number changes are announced through a role="status" region. The sheet traps focus and closes with Escape or the backdrop. The shake animation is turned off with prefers-reduced-motion.

Usage notes

Requires Bootstrap 5 and Bootstrap Icons; Plus Jakarta Sans is loaded from Google Fonts. The back arrow has no action; connect it to your router.

OTP Verification Screen with Code Inputs at a glance

Framework
Bootstrap 5
Code
HTML, CSS, JavaScript
JavaScript
Vanilla JavaScript, no jQuery
Dependencies
Bootstrap 5, Bootstrap Icons, fonts.googleapis.com
Layout
Mobile-first app screen, centred on wider screens
Category
Mobile Login & Sign Up
License
Free for personal and commercial use

Questions about this template

Can I use the OTP Verification Screen with Code Inputs code for free?

Yes. You can copy or download the code and use it in personal and commercial projects, including client work. No sign-up is needed. Reselling it as part of a component library or template collection is not allowed; see the license.

How do I add it to my website?

Load Bootstrap 5 and Bootstrap Icons and fonts.googleapis.com from a CDN (the links are under Requirements). Paste the HTML where the component should appear, add the CSS to your stylesheet and load the JavaScript before the closing </body> tag. Download HTML gives you a complete page with everything already linked.

Does it need jQuery or a JavaScript framework?

No. The script is plain vanilla JavaScript, so it works without jQuery, React or Vue. You can still use the markup inside those frameworks.

Can I turn this screen into an iOS or Android app?

Yes. It is plain HTML, CSS and JavaScript, so it works in a mobile website or progressive web app as it is. To ship it as a store app, put it in the web folder of a Capacitor or Cordova project and build it for iOS and Android; replace the sample data with calls to your own API.

How does it look on a desktop screen?

The screen is designed for phones. On wider screens it stays at phone width in the middle of the page, so it still looks like an app. The live demo opens at mobile width; use the Tablet and Desktop buttons to check other sizes.

Requirements

Add these to your page (already included in the download):

  • <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css">
  • <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
  • <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
  • <link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700&display=swap">
OTP Verification Screen with Code Inputs – Bootstrap 5 mobile login & sign up component screenshot
OTP Verification Screen with Code Inputs · Bootstrap 5 Mobile Login & Sign Up

More Mobile Login & Sign Up

Food Delivery App Phone Login – Bootstrap 6 mobile login & sign up preview

Food Delivery App Phone Login

Food delivery app phone login screen with searchable country code picker, SMS code step and continue as guest: a mobile phone number sign-in UI with a food photo header.