Create OTP Code Verification Form in HTML CSS & JavaScript

In today's digital landscape, ensuring the security of user accounts is paramount. One effective method for bolstering security while enhancing user experience is implementing OTP (One-Time Password) verification forms. In this article, we'll delve into the world of how to create OTP verification forms in HTML and Check Enter OTP is valid or not valid using JavaScript that offering insights and resources for seamless integration.

Understanding OTP Verification Forms in HTML

An OTP verification form serves as a gatekeeper, requiring users to validate their identity through a unique, one-time password sent via SMS or email. This additional layer of security mitigates the risk of unauthorized access and fortifies the authentication process.

Building Your OTP Verification Form: Leveraging HTML Templates

To expedite the development process, consider utilizing HTML templates, particularly those designed with Bootstrap framework. These templates offer a responsive, aesthetically pleasing layout while ensuring compatibility across various devices and browsers.

Key Features of OTP Verification HTML Template Bootstrap:

  • Responsive Design: Ensures optimal user experience across desktop and mobile devices.
  • Customizable Fields: Tailor the form to suit your specific authentication requirements.
  • Bootstrap Components: Leverage Bootstrap's pre-styled components for quick and easy integration.
  • Validation Mechanisms: Implement client-side and server-side validation to enhance form security.
  • OTP Generation: Integrate backend functionality to generate and validate one-time passwords.

Steps to Implement OTP Verification Form in HTML:

  1. Choose a Bootstrap OTP Verification Template: Select a template that aligns with your design preferences and functional needs.
  2. Customize the Template: Modify the HTML structure and CSS styles to reflect your branding and user interface preferences.
  3. Incorporate OTP Generation Logic: Integrate backend scripts to handle OTP generation and validation.
  4. Implement Form Submission Logic: Configure form submission handling to process user input and verify OTPs.
  5. Test and Iterate: Thoroughly test the OTP verification process to ensure seamless functionality and user experience.

Html Code :

<!DOCTYPE html>
    <title>OTP Code Verification Form</title>
      * {
        box-sizing: border-box;
      body {
        font-family: Arial, Helvetica, sans-serif;
        margin: 0;
        padding: 0;
      .container {
        width: 100%;
        max-width: 500px;
        margin: 0 auto;
        padding: 20px;
      h1 {
        text-align: center;
      form {
        background-color: #f2f2f2;
        border-radius: 5px;
        padding: 20px;
      input[type="number"] {
        width: 100%;
        padding: 12px 20px;
        margin: 8px 0;
        display: inline-block;
        border: 1px solid #ccc;
        border-radius: 4px;
        box-sizing: border-box;
      button[type="submit"] {
        background-color: #4CAF50;
        color: white;
        padding: 12px 20px;
        border: none;
        border-radius: 4px;
        cursor: pointer;
        width: 100%;
      button[type="submit"]:hover {
        background-color: #45a049;
    <div class="container">
      <h1>OTP Code Verification</h1>
      <form id="otpForm">
        <label for="otpCode">Enter the OTP code sent to your phone:</label>
        <input type="number" id="otpCode" name="otpCode" maxlength="6" minlength="6" required>
        <button type="submit">Verify OTP Code</button>
    <script src="script.js"></script>

CSS Code:

The CSS code above is embedded within the head of the HTML document.

JavaScript Code:

const form = document.getElementById("otpForm");
form.addEventListener("submit", function(event) {
  const otpCode = document.getElementById("otpCode").value;
  if (otpCode.length === 6 && /^\d+$/.test(otpCode)) {
    alert("OTP code is valid");
    // Here you can add your own code to send the OTP code to the server for validation.
  } else {
    alert("OTP code is invalid");


This code creates an OTP code verification form with one input field and a submit button. The input field is set to type "number" and has a minimum length and maximum length of 6, and is required. The JavaScript code adds an event listener to the form's submit event, preventing the default form submission behavior. It then gets the value of the OTP code input field and validates it using a regular expression that checks if the input contains exactly 6 digits. If the OTP code is valid, an alert is shown saying "OTP code is valid", and you can add your own code to send the OTP code to the server for validation. If the OTP code is invalid, an alert is shown saying "OTP code is invalid".


Incorporating an OTP verification form into your web application enhances security and instills trust among users. By leveraging HTML templates, specifically those built with Bootstrap, you can streamline the development process while delivering a polished, user-friendly authentication experience.

Empower your users with a robust authentication solution powered by OTP verification forms in HTML. Strengthen security, boost user confidence, and elevate your web application to new heights of reliability and trustworthiness.

Unlock the potential of OTP verification forms today and embark on a journey towards fortified user authentication.