Notes
HTML
CSS
JS
Tools
Code Snippets
HTML Entity
About
Contact Us
Show and Hide Password using JavaScript in Login Form
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>Show and Hide Password using JavaScript</title> </head> <body> <section> <div class="form-main-div"> <img src="https://www.teknowize.com/front-assets/images/logo/logo.svg" alt="logo"> <p class="heading">LOG IN</p> <form action="javascript:void(0)"> <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_1668194871.svg" alt="Mobile"> </div> </div> <div class="form-inner-div"> <div class="input-div"> <input type="password" class="form-control" placeholder="New Password"> <div class="auth-left-icon"> <img src="https://www.teknowize.com/attachments/file_1668193979.svg" alt="Mobile"> </div> <img src="https://www.teknowize.com/attachments/file_1668193813.svg" alt="Mobile" class="inputEyeIcon"> </div> <button type="submit" class="submitButton">Log in</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>Show and Hide Password using JavaScript</title> </head> <body> <section> <div class="form-main-div"> <img src="https://www.teknowize.com/front-assets/images/logo/logo.svg" alt="logo"> <p class="heading">LOG IN</p> <form action="javascript:void(0)"> <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_1668194871.svg" alt="Mobile"> </div> </div> <div class="form-inner-div"> <div class="input-div"> <input type="password" class="form-control" placeholder="New Password"> <div class="auth-left-icon"> <img src="https://www.teknowize.com/attachments/file_1668193979.svg" alt="Mobile"> </div> <img src="https://www.teknowize.com/attachments/file_1668193813.svg" alt="Mobile" class="inputEyeIcon"> </div> <button type="submit" class="submitButton">Log in</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 #00ff6a; 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 #B8B8B8; border-radius: 5px; 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; border: 1px solid #B8B8B8; border-radius: 5px; display: flex; justify-content: center; align-items: center; } .inputEyeIcon { position: absolute; top: 50%; right: 15px; transform: translateY(-50%); cursor: pointer; } .form-inner-div .submitButton { width: 250px; height: 50px; background: #000aff; border-radius: 8px; font-weight: 600; font-size: 20px; text-align: center; color: #FFFFFF; margin-top: 25px; border: 1.5px solid #000aff; cursor: pointer; } .form-inner-div .submitButton:hover { background: #ffffff; color: #000aff; } @media (max-width:672px) { .form-main-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; } .heading { font-size: 24px; font-weight: 700; color: #333; } .form-main-div { background: #fdfffd; border: 1px solid #00ff6a; 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 #B8B8B8; border-radius: 5px; 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; border: 1px solid #B8B8B8; border-radius: 5px; display: flex; justify-content: center; align-items: center; } .inputEyeIcon { position: absolute; top: 50%; right: 15px; transform: translateY(-50%); cursor: pointer; } .form-inner-div .submitButton { width: 250px; height: 50px; background: #000aff; border-radius: 8px; font-weight: 600; font-size: 20px; text-align: center; color: #FFFFFF; margin-top: 25px; border: 1.5px solid #000aff; cursor: pointer; } .form-inner-div .submitButton:hover { background: #ffffff; color: #000aff; } @media (max-width:672px) { .form-main-div { width: 100%; padding: 25px; } }
JS
// show hide password field var clearAllInputs = document.querySelectorAll('.inputEyeIcon'); clearAllInputs.forEach(function (clearEachInputs) { clearEachInputs.addEventListener('click', function (e) { var inputAll = this.parentElement.querySelector('input'); if (inputAll.type === "password") { inputAll.type = "text"; this.src = "https://www.teknowize.com/attachments/file_1668193773.svg"; } else { inputAll.type = "password"; this.src = "https://www.teknowize.com/attachments/file_1668193813.svg"; } }) });
Copied
// show hide password field var clearAllInputs = document.querySelectorAll('.inputEyeIcon'); clearAllInputs.forEach(function (clearEachInputs) { clearEachInputs.addEventListener('click', function (e) { var inputAll = this.parentElement.querySelector('input'); if (inputAll.type === "password") { inputAll.type = "text"; this.src = "https://www.teknowize.com/attachments/file_1668193773.svg"; } else { inputAll.type = "password"; this.src = "https://www.teknowize.com/attachments/file_1668193813.svg"; } }) });
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