Password
A password field with a show / hide button, and when someone makes a new password, a strength meter and a checklist that ticks off as they type. A note shows while Caps Lock is on.
Show and hide
Put the input in .password: the eye button is added for you. It keeps the caret where it was, and the field goes back to hidden when the form is sent.
<div class="form-field max-w-sm">
<label class="form-label" for="pw-1">Password</label>
<div class="password"><input class="form-control" id="pw-1" type="password" autocomplete="current-password"></div>
</div>Strength and rules
data-momo-strength adds four bars and a word: Too short, Weak, Okay, Good, Strong. data-momo-rules lists what you ask for: length:12, upper, lower, number, symbol.
<div class="form-field max-w-sm">
<label class="form-label" for="pw-2">New password</label>
<div class="password"><input class="form-control" id="pw-2" type="password" autocomplete="new-password" data-momo-strength data-momo-rules="length:12 upper number symbol"></div>
</div>Notes
- Use the right
autocomplete:current-passwordto sign in,new-passwordto make one. Password managers rely on it. - The score is a simple guide: length counts most, then mixing kinds of characters; repeats and runs like
1234count less. Check passwords on the server too.Momo.password.score(text)returns 0 to 4. - The rules list is linked to the field, so screen readers read it, and each rule says "done" when it is met.