Skip to content

Password Input

Password inputs are single-line text fields, but the text that is entered by the user is visually hidden by the browser — typically replaced with dots or asterisks for privacy. The common “show password” feature in login forms is achieved by dynamically changing the input type from "password" to "text" using JavaScript.

<form action="/login" method="post" name="loginForm">
<label for="password">Password:</label>
<input
type="password"
id="password"
name="password"
placeholder="Enter your password"
required
/>
<input type="checkbox" id="showPassword" onclick="togglePassword()" />
<label for="showPassword">Show Password</label>
<input type="submit" value="Log In" />
</form>
<script>
function togglePassword() {
const pwField = document.getElementById('password');
pwField.type = pwField.type === 'password' ? 'text' : 'password';
}
</script>