How to Create OTP Vertication Form in HTML
This tutorial will guide you through creating a OTP Vertication Form using HTML, CSS & JavaScript. Follow all the given step :
Step 1 : Create Index.html and add given html code on it.
Step 2 : Create style.css and add given css code on it.
Step 3 : Create index.js and add given JavaScript code on it.
HTML
HTML Code for OTP Vertication Form
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="style.css">
<title>OTP</title>
</head>
<body>
<div class="main">
<form>
<section>
<span>Enter Your 4 Digit OTP</span>
<div class="input_section">
<input type="text" id="box_1" autofocus="true" required maxlength="1" oninput="next()">
<input type="text" id="box_2" autofocus="false" required maxlength="1" oninput="next()">
<input type="text" id="box_3" autofocus="false" required maxlength="1" oninput="next()">
<input type="text" id="box_4" autofocus="false" required maxlength="1" oninput="next()">
</div>
<input type="submit" value="Verify OTP" class="btn" id="btn">
</section>
</form>
</div>
</body>
<script src="index.js"></script>
</html>
CSS
CSS Code for OTP Vertication Form
*
{
padding: 0;
margin: 0;
}
body{
padding: 0;
margin: 0;
font-family: serif;
}
.main{
width: 100%;
height: 100vh;
background-color: dodgerblue;
display: flex;
justify-content: center;
align-items: center;
}
span{
font-weight: bold;
}
section{
width: 250px;
height: 180px;
background-color: rgb(255,255,255);
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
border-radius: 10px;
}
.input_section{
margin: 20px 0;
}
input{
width: 40px;
height: 40px;
margin: 0 2px 0 2px;
border: none;
background-color: rgba(0,0,0,0.084);
border-radius: 5px;
font-size: 20px;
font-weight: bold;
outline: none;
text-align: center;
}
.btn{
width: 70%;
font-size: 15px;
background-color: rgba(255,166,0,0.341);
color: rgba(0,0,0,0.281);
border: none;
padding: 10px;
border-radius: 5px;
cursor: pointer;
}
JavaScript
JavaScript code for OTP Vertication Form
var box1 = document.getElementById("box_1");
var box2 = document.getElementById("box_2");
var box3 = document.getElementById("box_3");
var box4 = document.getElementById("box_4");
var btn = document.getElementById("btn")
function next() {
if(box1.value && box2.value && box3.value && box4.value)
{
btn.style.background = "orange";
btn.style.color = "black";
}
}
What is HTML
HTML, or HyperText Markup Language, is the standard markup language used to create and design documents on the World Wide Web. It's essentially the backbone of web pages, providing the structure and content that web browsers interpret and display.
HTML consists of a series of elements, which are enclosed by tags to define their purpose and function on a webpage. These elements can include headings, paragraphs, images, links, lists, forms, and more. By using a combination of HTML elements, web developers can organize and present information in a structured and visually appealing manner.
HTML is not a programming language but rather a markup language. This means it doesn't have the capability to perform calculations or execute complex logic like programming languages do. Instead, HTML focuses on describing the structure and content of a document, leaving the presentation and functionality to other technologies like CSS (Cascading Style Sheets) for styling and JavaScript for interactivity.
In summary, HTML serves as the foundation for building web pages, providing the structure and content necessary for browsers to render and display information to users on the internet.
What is CSS
CSS, or Cascading Style Sheets, is a language used to style the presentation of web documents written in HTML and XML. It provides a way to control the layout, colors, fonts, and other visual aspects of a webpage, enabling developers to create attractive and responsive designs. By separating content from presentation, CSS promotes cleaner code, easier maintenance, and greater flexibility in website design. With CSS, developers can achieve consistent branding, improved user experience, and better accessibility across various devices and screen sizes.
What is JavaScript
JavaScript is a versatile programming language used for creating dynamic and interactive web content. It enables developers to manipulate HTML elements, respond to user actions, and build seamless web applications. With its extensive ecosystem of libraries and frameworks, JavaScript powers both client-side and server-side development, making it an essential tool for modern web development.