Skip to main content

This is a draft (version 0.5.0). The National Information Technology Agency (NITA) plans to make GGDS official guidance for government websites after independent accessibility testing. What this means

Ghana Government Design System Design system for Government of Ghana websites – home Search

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, and autocomplete="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-shown and data-ggds-hidden on 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

Open this example on its own page

HTML code for “Password to sign in”
HTML
<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>
JSX (React)
<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

Open this example on its own page

HTML code for “Create a password, with an error”
HTML
<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>
JSX (React)
<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.css includes it. To load only the parts you use: core.css, then components/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:

JavaScript
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:

JavaScript
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 %}):

Text
class SignInForm(forms.Form):
    password = forms.CharField(widget=forms.PasswordInput)  # GGDSFormRenderer adds the Show button

Classes and states

Classes for password input
ClassWhat it does
.ggds-password-inputOn the field: a password with a Show button.
.ggds-password-input__wrapperThe input and the button, side by side, wrapping on a narrow screen.
.ggds-password-input__inputThe password input, as well as .ggds-input.
.ggds-password-input__toggleThe Show / Hide button, as well as .ggds-button--secondary. Hidden until the script runs.
States of password input
StateWhat 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.

Manual accessibility checks for password input
CheckResultNotes
Keyboard onlyNot tested yetWaiting for the external audit with disabled people (decision D-09).
NVDA screen reader with Firefox or Chrome (Windows)Not tested yetWaiting for the external audit with disabled people (decision D-09).
JAWS screen reader with Chrome (Windows)Not tested yetWaiting for the external audit with disabled people (decision D-09).
VoiceOver screen reader with Safari (iPhone)Not tested yetWaiting for the external audit with disabled people (decision D-09).
TalkBack screen reader with Chrome (Android)Not tested yetWaiting for the external audit with disabled people (decision D-09).
Zoom to 400%, and increased text spacingNot tested yetWaiting for the external audit with disabled people (decision D-09).
Windows contrast themes (forced colours)Not tested yetWaiting for the external audit with disabled people (decision D-09).
Voice control (Voice Access or Dragon)Not tested yetWaiting for the external audit with disabled people (decision D-09).

Changes

Changes to password input, newest first
VersionChange
0.4.0New 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.0Added.

Every change, in What’s new

Back to top

Something wrong, unclear or missing? Report a problem with this page or suggest a change to it on GitHub. You need a GitHub account.