<main>
  <div>
    <button>toggle security</button>
  </div>

  <form class="old-method">
    <h2>Classic Technique</h2>
    <input type="password" value="password">
    <p>Flop out <code>type="password"</code> for <code>type="text"</code> in HTML.</p>
    <p>⚠️ Downsides: doesn't play nice with all password managers.</p>
  </form>

  <form class="alt-1">
    <h2>WebKit-Specific Technique</h2>
    <input type="text" value="password">
    <p>Use <code>type="text"</code> with <code>-webkit-text-security</code> in CSS.</p>
    <p>⚠️ Downsides: Not using the sematically correct input type. Doesn't work in all browsers and probably never will.</p>
  </form>

  <form class="alt-2">
    <h2>Modern CSS Technique</h2>
    <input type="password" value="password">
    <p>Use <code>input-security</code> in CSS.</p>
    <p>⚠️ Downsides: Not supported in all browsers yet.</p>
  </form>
</main>
.alt-1 input {
  -webkit-text-security: square;
}
.show-passwords .alt-1 input {
  -webkit-text-security: none;
  /* https://developer.mozilla.org/en-US/docs/Web/CSS/-webkit-text-security */
}

.show-passwords .alt-2 input {
  input-security: none;
  /* https://drafts.csswg.org/css-ui/#input-security */
}

form {
  display: grid;
  grid-template-columns: 1fr minmax(300px, min-content) 1fr;
  background: #546e7a;
  box-shadow: inset 0 0 100px rgb(0 0 0 / 0.4);
  border-bottom: 1px solid rgba(255 255 255 / 0.4);
  border-top: 1px solid rgba(0 0 0 / 0.4);
  color: white;
  padding: 2rem;
}
form > * {
  grid-column: 2 / 3;
}
html {
  font: 100%/1.4 system-ui;
}
h2 {
  margin: 0 0 0.5rem 0;
}
p {
  margin: 0.5rem 0;
}
body {
  margin: 0;
}
main div {
  background: #f4511e;
  text-align: center;
  padding: 2rem;
  position: sticky;
  top: 0;
}
button {
  border: 0;
  font: 130%/1.4 system-ui;
  background: white;
  border-radius: 6px;
  padding: 0.5rem 2rem;
}
button:hover,
button:focus {
  background: #eee;
}
button:active {
  position: relative;
  top: 1px;
}
input {
  font: 150%/1.4 system-ui;
}
const button = document.querySelector("button");
const oldMethodInput = document.querySelector(".old-method input");

button.addEventListener("click", () => {
  document.documentElement.classList.toggle("show-passwords");
  if (oldMethodInput.getAttribute("type") === "password") {
    oldMethodInput.setAttribute("type", "text");
  } else {
    oldMethodInput.setAttribute("type", "password");
  }
});

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.