Skip to main content
Login Join
Snippet · HTML

Show/Hide Password Field

Shared by Darshit Rajyaguru · May 14, 2026

23 views
1 upvote
Back to Snippets

Allows users to toggle password visibility.

<input type="password" id="password">
<button onclick="togglePassword()">Show</button>

<script>
function togglePassword() {

	const password = document.getElementById('password');

	password.type = password.type === 'password'
		? 'text'
		: 'password';

}
</script>
Know a different way to do this? Add your approach as a variation so folks can compare them side by side.
Submit a variation

0 comments