Two ways
<!DOCTYPE html>
<html>
<body>
<button type="button"
onclick="document.getElementById('pass').type = 'password'">
Hide</button>
<button type="button"
onclick="document.getElementById('pass').type = 'text'">
Show</button>
<input id="pass" type="password" value="RickAstley">
</body>
</html>
<!DOCTYPE html>
<html>
<body>
<!-- Password field -->
Password: <input type="password" value="FakePSW" id="myInput">
<!-- An element to toggle between password visibility -->
<input type="checkbox" onclick="myFunction()">Show Password
function myFunction() {
var x = document.getElementById("myInput");
if (x.type === "password") {
x.type = "text";
} else {
x.type = "password";
}
}
</body
</html>