<input type="password" id="password">
<button onclick="switchVisibility()">show / hide</button>
const passwordField = document.querySelector('#password')

function switchVisibility() {
  if (passwordField.getAttribute('type') === 'password') passwordField.setAttribute('type', 'text')
  else passwordField.setAttribute('type', 'password')
}
Run Pen

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.