HTML
One input and one named toggle button.
<input id="password" type="password">
<button type="button" aria-pressed="false">Show password</button>Authentication · Concept
A show-password control changes presentation, preserves the value, stays focused, and exposes its pressed state.
The principle
Use a real toggle button. Keep its label stable and communicate state with aria-pressed.
Interactive demo
The password value and button focus survive every visibility change. The state is both visible and programmatic.
Password is hidden.
Implementation
The button’s visible label remains “Show password.” Pressed state means the requested presentation is active. Avoid replacing the input, losing its value, or moving focus back to it unexpectedly.
One input and one named toggle button.
<input id="password" type="password">
<button type="button" aria-pressed="false">Show password</button>Update type, pressed state, and visible explanation.
input.type = shown ? 'text' : 'password';
button.setAttribute('aria-pressed', shown);
state.textContent = shown ? 'Password is visible.' : 'Password is hidden.';Quick test