Password field with an eye toggle. The field is a real type="password"; showing the text takes a few lines of your own JavaScript.
Structure
| Class | Example |
|---|---|
|
.mdst-password-input .mdst-input |
|
States
| Attribute | Example |
|---|---|
| placeholder |
|
| disabled |
|
Multiple Instances
The field is a real type="password", so browsers, password managers, and screen readers treat it as one. The eye toggle is a checkbox styled with CSS, and its icon swaps on its own. Showing the text needs a few lines of your own JavaScript to switch the field's type; the script on this page is an example, not part of modest-ui. Without it, the field stays a normal, masked password field.
Usage
<!-- Basic password input -->
<div class="mdst-password-input">
<input type="password" autocomplete="current-password" class="mdst-input" placeholder="Enter password" />
<input type="checkbox" name="password-toggle" aria-label="Toggle password visibility" />
</div>
<!-- Disabled -->
<div class="mdst-password-input">
<input type="password" autocomplete="current-password" class="mdst-input" placeholder="Disabled" disabled />
<input type="checkbox" name="password-toggle" aria-label="Toggle password visibility" disabled />
</div>
<!-- Multiple instances (no IDs needed) -->
<div class="mdst-password-input">
<input type="password" autocomplete="current-password" class="mdst-input" placeholder="Current password" />
<input type="checkbox" name="password-toggle" aria-label="Toggle password visibility" />
</div>
<div class="mdst-password-input">
<input type="password" autocomplete="new-password" class="mdst-input" placeholder="New password" />
<input type="checkbox" name="password-toggle" aria-label="Toggle password visibility" />
</div>
<script>
// Example: show or hide the text when the eye toggle changes
document.querySelectorAll(".mdst-password-input > input[type=checkbox]").forEach((toggle) => {
toggle.addEventListener("change", () => {
const field = toggle.parentElement.querySelector("input:not([type=checkbox])");
field.type = toggle.checked ? "text" : "password";
});
});
</script>