Forms
Password input
A password field with a Show button, so people can check what they typed before they send it.
When to use
- When people sign in, or create or change a password.
When not to use
- For a one-time code sent by SMS or email. Use a code input: it is not secret once used.
- For a PIN: never ask for a mobile money or bank PIN on a website. People enter it on their phone.
How to use
- Use the label "Password". When people create one, say what it needs in the hint, and only rules your system really has.
- Set
autocomplete="current-password"to sign in, andautocomplete="new-password"to create one, so password managers can fill and suggest it. - Let people paste. Do not limit the length to less than 64 characters.
- Add
data-ggds-module="password-input". The GGDS script shows the Show button, switches it to Hide, and hides the password again when the form is sent, so the browser does not keep it as plain text. - The button's words can be translated:
data-ggds-show,data-ggds-hide,data-ggds-show-label,data-ggds-hide-label,data-ggds-shownanddata-ggds-hiddenon the field. The React, Astro and Django parts set them from GGDS's text in the page's language.
Accessibility
What GGDS does
- The button says what it does ("Show password") and screen readers hear "Your password is visible" when it changes.
- The password goes back to hidden when the form is sent.
- Without JavaScript there is no button, and the field still works.
What you need to do
- Never stop people pasting into the field (WCAG 3.3.8, accessible authentication).
- If sign-in fails, say "The phone number or password is not right", without saying which.
Example: Password to sign in
<div class="ggds-field ggds-password-input" data-ggds-module="password-input">
<label class="ggds-label" for="password">Password</label>
<div class="ggds-password-input__wrapper">
<input class="ggds-input ggds-password-input__input" id="password" name="password" type="password" autocomplete="current-password" spellcheck="false" autocapitalize="none">
<button class="ggds-button ggds-button--secondary ggds-password-input__toggle" type="button" aria-controls="password" aria-label="Show password" hidden>Show</button>
</div>
</div><div className="ggds-field ggds-password-input" data-ggds-module="password-input">
<label className="ggds-label" htmlFor="password">Password</label>
<div className="ggds-password-input__wrapper">
<input className="ggds-input ggds-password-input__input" id="password" name="password" type="password" autoComplete="current-password" spellCheck="false" autocapitalize="none" />
<button className="ggds-button ggds-button--secondary ggds-password-input__toggle" type="button" aria-controls="password" aria-label="Show password" hidden>Show</button>
</div>
</div>Example: Create a password, with an error
<div class="ggds-field ggds-field--error ggds-password-input" data-ggds-module="password-input">
<label class="ggds-label" for="new-password">Create a password</label>
<p class="ggds-hint" id="new-password-hint">At least 8 characters</p>
<p class="ggds-error-message" id="new-password-error"><span class="ggds-visually-hidden">Error:</span> Your password must have at least 8 characters</p>
<div class="ggds-password-input__wrapper">
<input class="ggds-input ggds-password-input__input" id="new-password" name="newPassword" type="password" autocomplete="new-password" spellcheck="false" autocapitalize="none" aria-describedby="new-password-hint new-password-error" aria-invalid="true">
<button class="ggds-button ggds-button--secondary ggds-password-input__toggle" type="button" aria-controls="new-password" aria-label="Show password" hidden>Show</button>
</div>
</div><div className="ggds-field ggds-field--error ggds-password-input" data-ggds-module="password-input">
<label className="ggds-label" htmlFor="new-password">Create a password</label>
<p className="ggds-hint" id="new-password-hint">At least 8 characters</p>
<p className="ggds-error-message" id="new-password-error"><span className="ggds-visually-hidden">Error:</span> Your password must have at least 8 characters</p>
<div className="ggds-password-input__wrapper">
<input className="ggds-input ggds-password-input__input" id="new-password" name="newPassword" type="password" autoComplete="new-password" spellCheck="false" autocapitalize="none" aria-describedby="new-password-hint new-password-error" aria-invalid="true" />
<button className="ggds-button ggds-button--secondary ggds-password-input__toggle" type="button" aria-controls="new-password" aria-label="Show password" hidden>Show</button>
</div>
</div>Use it
- Stylesheet
ggds.cssincludes it. To load only the parts you use:core.css, thencomponents/password-input.css(0.2 KB with gzip, minified).- JavaScript
- Optional: @ggds/js shows the Show button, switches the field between hidden and visible, tells screen readers which it is, and hides the password again when the form is sent. Without it, a normal password field.
HTML
Copy the HTML under each example above. It works in any website.
Astro
With @ggds/astro:
import PasswordInput from '@ggds/astro/PasswordInput.astro';
---
import PasswordInput from '@ggds/astro/PasswordInput.astro';
---
<PasswordInput id="password" name="password" label="Password" />React and Next.js
With @ggds/react:
import { PasswordInput } from '@ggds/react';
<PasswordInput id="password" name="password" label="Password"
error={errors.password} /> {/* the Show button appears once the page's JavaScript runs */}Django
With ggds-django ({% load ggds %}):
class SignInForm(forms.Form):
password = forms.CharField(widget=forms.PasswordInput) # GGDSFormRenderer adds the Show buttonClasses and states
| Class | What it does |
|---|---|
.ggds-password-input | On the field: a password with a Show button. |
.ggds-password-input__wrapper | The input and the button, side by side, wrapping on a narrow screen. |
.ggds-password-input__input | The password input, as well as .ggds-input. |
.ggds-password-input__toggle | The Show / Hide button, as well as .ggds-button--secondary. Hidden until the script runs. |
| State | What it does |
|---|---|
aria-label="Hide password" | The password is visible. |
Accessibility tests
Automated, on every change
These run each time GGDS changes. A change that fails one is not accepted.
- WCAG 2.2 A and AA rules (axe), at desktop and phone widths, on every example
- No sideways scrolling on a 320px screen, also with a wide font, on every example
- Every approved colour pair meets its contrast minimum, for every institution theme
- No inline scripts or styles, so it runs under a strict Content Security Policy
- Behaviour test: “password input: Show reveals the password, says so, and hides it again when the form is sent”
By people, with assistive technology
Automated tests find only some of the barriers people meet. These checks are still to be done.
| Check | Result | Notes |
|---|---|---|
| Keyboard only | Not tested yet | Waiting for the external audit with disabled people (decision D-09). |
| NVDA screen reader with Firefox or Chrome (Windows) | Not tested yet | Waiting for the external audit with disabled people (decision D-09). |
| JAWS screen reader with Chrome (Windows) | Not tested yet | Waiting for the external audit with disabled people (decision D-09). |
| VoiceOver screen reader with Safari (iPhone) | Not tested yet | Waiting for the external audit with disabled people (decision D-09). |
| TalkBack screen reader with Chrome (Android) | Not tested yet | Waiting for the external audit with disabled people (decision D-09). |
| Zoom to 400%, and increased text spacing | Not tested yet | Waiting for the external audit with disabled people (decision D-09). |
| Windows contrast themes (forced colours) | Not tested yet | Waiting for the external audit with disabled people (decision D-09). |
| Voice control (Voice Access or Dragon) | Not tested yet | Waiting for the external audit with disabled people (decision D-09). |
Changes
| Version | Change |
|---|---|
| 0.4.0 | New components for services that take people from start to payment, in HTML, React, Astro and Django, each checked element by element against its documentation example and with axe on phones and computers. All are alpha. |
| 0.1.0 | Added. |
Related components
Something wrong, unclear or missing? or suggest a change to it on GitHub. You need a GitHub account.