In this video tutorial, you will learn how to create password show and hide toggle using HTML CSS and JavaScript, also label up animation on the input field with color animation. When you focus on the input field all animation happens and to show or hide the password that you typed then you need to click on the eye button or icon.

Timestamps:
00:00 Password show hide on input box | Demo
00:57 HTML code to make Input field
01:43 CSS code for input field
05:40 Input field animation on focus
07:22 JavaScript code to show and hide password
 

Source Code:

HTML File:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <!----==== CSS ====-->
    <link rel="stylesheet" href="style.css">
    
    <!----==== Icounscout Link ====-->
    <link rel="stylesheet" href="https://unicons.iconscout.com/release/v4.0.0/css/line.css">
    
     <title>Password Show & Hide</title>
</head>
<body>
    <div class="container">
        <div class="input-box">
            <input type="password" spellcheck="false" required>
            <label for="">Password</label>
            <i class="uil uil-eye-slash toggle"></i>
        </div>
    </div>
    <script>
        const toggle = document.querySelector(".toggle"),
              input = document.querySelector("input");
              toggle.addEventListener("click", () =>{
                  if(input.type ==="password"){
                    input.type = "text";
                    toggle.classList.replace("uil-eye-slash", "uil-eye");
                  }else{
                    input.type = "password";
                  }
              })
    </script>
</body>
</html>

CSS Files

/* Google Font Import - Poppins */
@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&display=swap');
*{
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Poppins', sans-serif;
}
body{
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #4070f4;
}
.container{
    position: relative;
    max-width: 340px;
    width: 100%;
    padding: 20px;
    border-radius: 6px;
    background-color: #fff;
}
.container .input-box{
    position: relative;
    height: 50px;
}
.input-box input{
    position: absolute;
    height: 100%;
    width: 100%;
    outline: none;
    border: 2px solid #ccc;
    border-radius: 6px;
    padding: 0 35px 0 15px;
    transition: all 0.2s linear;
}
input:is(:focus, :valid){
    border-color: #4070f4;
}
.input-box :is(label, i){
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    color: #999;
    transition: all 0.2s linear;
}
.input-box label{
    left: 15px;
    pointer-events: none;
    font-size: 16px;
    font-weight: 400;
}
input:is(:focus, :valid) ~ label{
    color: #4070f4;
    top: 0;
    font-size: 12px;
    font-weight: 500;
    background-color: #fff;
}
.input-box i{
    right: 15px;
    cursor: pointer;
    font-size: 20px;
}
input:is(:focus, :valid) ~ i{
    color: #4070f4;
}

Download Code Files

Subscribe: https://www.youtube.com/@CodingLabYT/featured 

#html #css #javascript 

Create a Password Show/Hide Toggle with HTML, CSS, and JavaScript
3.45 GEEK