Password Visibility Toggle Form Template

Help users avoid typos by letting them see their password with this visibility toggle button.

This template adds a common "eye" icon to a password field that, when clicked, toggles the input between a password type (dots) and a text type (readable characters), greatly improving usability.

Screenshot of a password input field with an 'eye' icon to toggle visibility.

Get Source Code → Preview →

About this Password Visibility Toggle

Entering complex passwords can be difficult, and the obscured "dots" make it impossible to spot a typo. A visibility toggle solves this problem. This template provides a self-contained component consisting of an input field and a clickable toggle button, typically represented by an eye icon.

The logic is handled by a simple JavaScript snippet:

  1. The input field defaults to type="password".
  2. A button with an eye icon is placed next to or inside the input field.
  3. When the user clicks the button, the JavaScript checks the current type of the input field.
    • If it's 'password', it changes it to 'text' and swaps the icon to an "eye-slashed" icon to indicate the password is now visible.
    • If it's 'text', it reverts it back to 'password' and the original icon.

This small feature can significantly reduce user frustration and login/signup failures due to password typos.

Features

Dependencies

Uses pure HTML and CSS, with a necessary, self-contained JavaScript block for the toggle functionality.

Code

Here's the full code for the password field with a visibility toggle:

View Output