Mon - Sun 8.00 AM - 8.00 PM
[email protected]
Home
Articles
Our Courses
HTML 5
CSS
JavaScript
MySql
PHP
Laravel
Bootstrap
Our Tutorials
PHP
JavaScript
HTML
Laravel
MySQL
JQuery
CSS
Git
Bootstrap
Vue JS
Android
Ui Code Snippets
Chat Box
Range Slider
Radio Button
Select Box
Nav Bar
Other
Testimonial
Carousel
Logo
Loader
Lightbox
Login Form
Modals
OTP Verification Form
Popular Notes
HTML
CSS
JavaScript
SQL
Services
About
Contact Us
Ui Code
Snippets
Login Form With Clear Input Fields on Click Using HTML CSS and 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>Clear Form Inputs Field on Click Using HTML CSS and Javascript</title> </head> <body> <section> <div class="form-main-div"> <img src="https://www.teknowize.com/front-assets/images/logo/logo.png" alt="logo"> <p class="heading">LOG IN</p> <form action="javascript:void(0)"> <div class="form-inner-div"> <div class="input-div"> <input type="text" class="form-control" placeholder="Email Address"> <div class="auth-left-icon"> <img src="https://www.teknowize.com/attachments/file_1668268206.svg" alt="message"> </div> <img src="https://www.teknowize.com/attachments/file_1668268361.svg" alt="Clear" class="clearInputIcon"> </div> <button type="submit" class="submitButton">Send 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; } .heading { font-size: 24px; font-weight: 700; color: #333; } .form-main-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; } .form-inner-div { position: relative; width: 100%; } .input-div { position: relative; max-width: 370px; margin: 0 auto; margin-top: 1rem; } .input-div input { width: 100%; border: 1px solid #0044ff; border-radius: 50px; height: 50px; padding: 0 1.5rem 0 3.5rem; font-size: 18px; color: #333333; } .input-div input:focus { outline: none; box-shadow: none; } .input-div input::placeholder { font-size: 18px; color: #B0B0B0; } .input-div .auth-left-icon { position: absolute; left: 0; top: 0; width: 50px; height: 50px; background: #0044ff; border: 1px solid #0044ff; border-radius: 50%; display: flex; justify-content: center; align-items: center; } .clearInputIcon { position: absolute; top: 50%; right: 15px; transform: translateY(-50%); cursor: pointer; } .form-inner-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; } .form-inner-div .submitButton:hover { background: #ffffff; color: #00d17a; } @media (max-width:672px) { .form-main-div { width: 100%; padding: 25px; } }
JS
// clear each inputs var clearAllInputs = document.querySelectorAll('.clearInputIcon'); clearAllInputs.forEach(function (clearEachInputs) { clearEachInputs.addEventListener('click', function (e) { this.parentElement.firstElementChild.value = ""; }) });
Output