Notes
HTML
CSS
JS
Tools
Code Snippets
HTML Entity
About
Contact Us
How to Create OTP Input Field Using HTML , CSS & Javascript
HTML
CSS
JS
Output
HTML
<html lang="en"> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <head> <title>How to Create OTP Input Field Using HTML , CSS & Javascript</title> </head> <body> <section> <div class="main-form-div"> <img src="https://www.teknowize.com/front-assets/images/logo/logo.svg" alt="logo"> <p class="form-heading-para">OTP FORM</p> <form action="javascript:void(0)"> <div class="inner-form-div"> <div class="all-inputs-div"> <input type="text" class="form-control" placeholder="1" maxlength=1 oninput='digitValidate(this)' onkeyup='tabChange(1)'> <input type="text" class="form-control" placeholder="2" maxlength=1 oninput='digitValidate(this)' onkeyup='tabChange(2)'> <input type="text" class="form-control" placeholder="3" maxlength=1 oninput='digitValidate(this)' onkeyup='tabChange(3)'> <input type="text" class="form-control" placeholder="4" maxlength=1 oninput='digitValidate(this)' onkeyup='tabChange(4)'> </div> <button type="submit" class="submitButton">Verify OTP</button> </div> </form> </div> </section> </body> </html>
Copied
<html lang="en"> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <head> <title>How to Create OTP Input Field Using HTML , CSS & Javascript</title> </head> <body> <section> <div class="main-form-div"> <img src="https://www.teknowize.com/front-assets/images/logo/logo.svg" alt="logo"> <p class="form-heading-para">OTP FORM</p> <form action="javascript:void(0)"> <div class="inner-form-div"> <div class="all-inputs-div"> <input type="text" class="form-control" placeholder="1" maxlength=1 oninput='digitValidate(this)' onkeyup='tabChange(1)'> <input type="text" class="form-control" placeholder="2" maxlength=1 oninput='digitValidate(this)' onkeyup='tabChange(2)'> <input type="text" class="form-control" placeholder="3" maxlength=1 oninput='digitValidate(this)' onkeyup='tabChange(3)'> <input type="text" class="form-control" placeholder="4" maxlength=1 oninput='digitValidate(this)' onkeyup='tabChange(4)'> </div> <button type="submit" class="submitButton">Verify OTP</button> </div> </form> </div> </section> </body> </html>
CSS
* { box-sizing: border-box; margin: 0; padding: 0; } body { display: flex; justify-content: center; align-items: center; } section { width: 100%; display: flex; justify-content: center; } .form-heading-para { font-size: 24px; font-weight: 700; color: #333; } .main-form-div { background: #fdfffd; border: 1px solid #c300ff; box-shadow: 2px 2px 15px rgba(0, 0, 0, 0.03); border-radius: 8px; padding: 60px; text-align: center; margin-top: 30px; width: 640px; } .inner-form-div { position: relative; width: 100%; } .all-inputs-div { max-width: 370px; margin: 0 auto; margin-top: 1rem; display: flex; justify-content: space-between; } .all-inputs-div input { width: 100%; border: 1px solid #0044ff; border-radius: 5px; height: 50px; padding: 0 0.5rem; font-size: 18px; color: #333333; text-align: center; margin-left: 0.5rem; } .all-inputs-div input::placeholder { color: rgb(241, 240, 240); } .all-inputs-div input:first-child { margin-left: 0; } .all-inputs-div input:focus { outline: none; box-shadow: none; } .inner-form-div .submitButton { width: 250px; height: 50px; background: #00d17a; border-radius: 8px; font-weight: 600; font-size: 20px; text-align: center; color: #FFFFFF; margin-top: 25px; border: 1.5px solid #00d17a; cursor: pointer; } .inner-form-div .submitButton:hover { background: #ffffff; color: #00d17a; } @media (max-width:672px) { .main-form-div { width: 100%; padding: 25px; } }
Copied
* { box-sizing: border-box; margin: 0; padding: 0; } body { display: flex; justify-content: center; align-items: center; } section { width: 100%; display: flex; justify-content: center; } .form-heading-para { font-size: 24px; font-weight: 700; color: #333; } .main-form-div { background: #fdfffd; border: 1px solid #c300ff; box-shadow: 2px 2px 15px rgba(0, 0, 0, 0.03); border-radius: 8px; padding: 60px; text-align: center; margin-top: 30px; width: 640px; } .inner-form-div { position: relative; width: 100%; } .all-inputs-div { max-width: 370px; margin: 0 auto; margin-top: 1rem; display: flex; justify-content: space-between; } .all-inputs-div input { width: 100%; border: 1px solid #0044ff; border-radius: 5px; height: 50px; padding: 0 0.5rem; font-size: 18px; color: #333333; text-align: center; margin-left: 0.5rem; } .all-inputs-div input::placeholder { color: rgb(241, 240, 240); } .all-inputs-div input:first-child { margin-left: 0; } .all-inputs-div input:focus { outline: none; box-shadow: none; } .inner-form-div .submitButton { width: 250px; height: 50px; background: #00d17a; border-radius: 8px; font-weight: 600; font-size: 20px; text-align: center; color: #FFFFFF; margin-top: 25px; border: 1.5px solid #00d17a; cursor: pointer; } .inner-form-div .submitButton:hover { background: #ffffff; color: #00d17a; } @media (max-width:672px) { .main-form-div { width: 100%; padding: 25px; } }
JS
// OTP field full validation let digitValidate = function (ele) { ele.value = ele.value.replace(/[^0-9]/g, ''); } let tabChange = function (val) { let ele = document.querySelectorAll('input'); if (ele[val - 1].value != '') { ele[val].focus() } else if (ele[val - 1].value == '') { ele[val - 2].focus() } }
Copied
// OTP field full validation let digitValidate = function (ele) { ele.value = ele.value.replace(/[^0-9]/g, ''); } let tabChange = function (val) { let ele = document.querySelectorAll('input'); if (ele[val - 1].value != '') { ele[val].focus() } else if (ele[val - 1].value == '') { ele[val - 2].focus() } }
Output
Our Courses
HTML 5
CSS
JavaScript
MySql
PHP
Laravel
Bootstrap
Programming Tutorial
PHP
JavaScript
HTML
Laravel
MySQL
JQuery
CSS
Git
Bootstrap
Vue JS
Android
Python
Server
Code Snippets
Chat Box
Range Slider
Radio Button
Select Box
Nav Bar
Other
Testimonial
Carousel
Logo
Loader
Lightbox
Forms
Popup
Table
HTML Course Code
HTML Entity
↑→ Arrows
$¢ Currency
Aö Letters
%+ Math
1¾ Numbers
&— Punctuation
©™ Symbols
Best Of
Internet
Technology
Health
Travel
Onine Tools
CSS Minifier
Text Converter
Age Calculator
Pincode Details
Whiteboard
PDF to Text
Gradient Generator
PX to REM Converter
REM to PX Converter
PX to EM Converter
EM to PX Converter
WEBP Converter
Latest & Upcoming movies
Bollywood
Hollywood
Tamil
Telgu
Bangla
Web Series
Notes
HTML
CSS
JS