How to toggle password visibility

Use JavaScript to toggle the visibility of the password.

Password:

Show Password

Toggle password visibility

Step 1 - Add HTML:

<!-- Password field -->
Password: <input type="password" value="FakePSW" id="myInput">
<!-- An element for toggling password visibility -->
<input type="checkbox" onclick="myFunction()">Show Password

Step 2 - Add JavaScript:

function myFunction() {
  var x = document.getElementById("myInput");
  if (x.type === "password") {
    x.type = "text";
  }
    x.type = "password";
  }
}

Try It Yourself