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

Text input, textarea, select and file upload

A single form question with a label, an optional hint and an error message.

When to use

  • To ask one question with a typed or chosen answer.

When not to use

How to use

  • Every field has a visible label.
  • Put extra help in a hint under the label, and connect it with aria-describedby.
  • On error: add ggds-field--error, an error message starting with a hidden "Error:", and aria-invalid="true" on the input. Also list it in the error summary.
  • Use autocomplete for personal details such as name, phone and email.
  • For an amount or a measurement, put the unit beside the input with ggds-input__prefix (GH₵) or ggds-input__suffix (kg) inside ggds-input-wrapper. Say the unit in the label as well ("in Ghana cedis"): the prefix and suffix are hidden from screen readers. Use inputmode="decimal", not type="number".

Do

  • Say how to fix an error: "Enter your phone number".
  • Size the input to the answer: short for a code, long for a name.

Don't

  • Use placeholder text instead of a label.
  • Write "Invalid input".

Accessibility

What GGDS does

  • Text is at least 16px, so phones do not zoom in, and every control is at least 44px tall.
  • An error is shown by more than colour: a message, a line beside the question and a red border.
  • The gold focus ring shows on every control.

What you need to do

  • Give every field a visible <label>; never use placeholder text instead.
  • Connect the hint and error message with aria-describedby, hint first.
  • On error, add aria-invalid="true" and start the message with a visually hidden "Error:".
  • Add autocomplete to personal details, so people can fill them in quickly.

Example: Text input with hint

Open this example on its own page

HTML code for “Text input with hint”
HTML
<div class="ggds-field">
  <label class="ggds-label" for="full-name">Full name</label>
  <p class="ggds-hint" id="full-name-hint">As shown on your Ghana Card</p>
  <input class="ggds-input ggds-input--width-long" id="full-name" name="fullName" type="text" autocomplete="name" spellcheck="false" aria-describedby="full-name-hint">
</div>
JSX (React)
<div className="ggds-field">
  <label className="ggds-label" htmlFor="full-name">Full name</label>
  <p className="ggds-hint" id="full-name-hint">As shown on your Ghana Card</p>
  <input className="ggds-input ggds-input--width-long" id="full-name" name="fullName" type="text" autoComplete="name" spellCheck="false" aria-describedby="full-name-hint" />
</div>

Example: Text input with an error

Open this example on its own page

HTML code for “Text input with an error”
HTML
<div class="ggds-field ggds-field--error">
  <label class="ggds-label" for="phone">Mobile phone number</label>
  <p class="ggds-hint" id="phone-hint">For example, 024 123 4567</p>
  <p class="ggds-error-message" id="phone-error"><span class="ggds-visually-hidden">Error:</span> Enter a mobile phone number with 10 digits, like 024 123 4567</p>
  <input class="ggds-input ggds-input--width-medium" id="phone" name="phone" type="tel" autocomplete="tel" inputmode="tel" aria-invalid="true" aria-describedby="phone-hint phone-error" value="024 123">
</div>
JSX (React)
<div className="ggds-field ggds-field--error">
  <label className="ggds-label" htmlFor="phone">Mobile phone number</label>
  <p className="ggds-hint" id="phone-hint">For example, 024 123 4567</p>
  <p className="ggds-error-message" id="phone-error"><span className="ggds-visually-hidden">Error:</span> Enter a mobile phone number with 10 digits, like 024 123 4567</p>
  <input className="ggds-input ggds-input--width-medium" id="phone" name="phone" type="tel" autoComplete="tel" inputMode="tel" aria-invalid="true" aria-describedby="phone-hint phone-error" defaultValue="024 123" />
</div>

Example: Textarea

Open this example on its own page

HTML code for “Textarea”
HTML
<div class="ggds-field">
  <label class="ggds-label" for="problem">What happened?</label>
  <p class="ggds-hint" id="problem-hint">Include dates and any reference numbers. Do not include your PIN or passwords.</p>
  <textarea class="ggds-textarea" id="problem" name="problem" rows="5" aria-describedby="problem-hint"></textarea>
</div>
JSX (React)
<div className="ggds-field">
  <label className="ggds-label" htmlFor="problem">What happened?</label>
  <p className="ggds-hint" id="problem-hint">Include dates and any reference numbers. Do not include your PIN or passwords.</p>
  <textarea className="ggds-textarea" id="problem" name="problem" rows={5} aria-describedby="problem-hint"></textarea>
</div>

Example: Select

Open this example on its own page

HTML code for “Select”
HTML
<div class="ggds-field">
  <label class="ggds-label" for="region">Region</label>
  <select class="ggds-select" id="region" name="region" autocomplete="address-level1">
    <option value="">Choose a region</option>
    <option>Ahafo</option>
    <option>Ashanti</option>
    <option>Bono</option>
    <option>Bono East</option>
    <option>Central</option>
    <option>Eastern</option>
    <option>Greater Accra</option>
    <option>North East</option>
    <option>Northern</option>
    <option>Oti</option>
    <option>Savannah</option>
    <option>Upper East</option>
    <option>Upper West</option>
    <option>Volta</option>
    <option>Western</option>
    <option>Western North</option>
  </select>
</div>
JSX (React)
<div className="ggds-field">
  <label className="ggds-label" htmlFor="region">Region</label>
  <select className="ggds-select" id="region" name="region" autoComplete="address-level1">
    <option value="">Choose a region</option>
    <option>Ahafo</option>
    <option>Ashanti</option>
    <option>Bono</option>
    <option>Bono East</option>
    <option>Central</option>
    <option>Eastern</option>
    <option>Greater Accra</option>
    <option>North East</option>
    <option>Northern</option>
    <option>Oti</option>
    <option>Savannah</option>
    <option>Upper East</option>
    <option>Upper West</option>
    <option>Volta</option>
    <option>Western</option>
    <option>Western North</option>
  </select>
</div>

Example: File upload

Open this example on its own page

HTML code for “File upload”
HTML
<div class="ggds-field">
  <label class="ggds-label" for="evidence">Upload a photo or document (optional)</label>
  <p class="ggds-hint" id="evidence-hint">PDF, JPG or PNG, up to 5 MB</p>
  <input class="ggds-file-upload" id="evidence" name="evidence" type="file" accept=".pdf,.jpg,.jpeg,.png" aria-describedby="evidence-hint">
</div>
JSX (React)
<div className="ggds-field">
  <label className="ggds-label" htmlFor="evidence">Upload a photo or document (optional)</label>
  <p className="ggds-hint" id="evidence-hint">PDF, JPG or PNG, up to 5 MB</p>
  <input className="ggds-file-upload" id="evidence" name="evidence" type="file" accept=".pdf,.jpg,.jpeg,.png" aria-describedby="evidence-hint" />
</div>

Example: States: empty, answered, focus and error

Open this example on its own page

HTML code for “States: empty, answered, focus and error”
HTML
<div class="ggds-field">
  <label class="ggds-label" for="state-empty">Empty</label>
  <input class="ggds-input ggds-input--width-medium" id="state-empty" name="stateEmpty" type="text">
</div>
<div class="ggds-field">
  <label class="ggds-label" for="state-answered">Answered</label>
  <input class="ggds-input ggds-input--width-medium" id="state-answered" name="stateAnswered" type="text" value="Kofi Mensah">
</div>
<div class="ggds-field">
  <label class="ggds-label" for="state-focus">Focus (what keyboard users see)</label>
  <input class="ggds-input ggds-input--width-medium" id="state-focus" name="stateFocus" type="text">
</div>
<div class="ggds-field ggds-field--error">
  <label class="ggds-label" for="state-error">Error</label>
  <p class="ggds-error-message" id="state-error-message"><span class="ggds-visually-hidden">Error:</span> Enter your full name</p>
  <input class="ggds-input ggds-input--width-medium" id="state-error" name="stateError" type="text" aria-invalid="true" aria-describedby="state-error-message">
</div>
JSX (React)
<>
  <div className="ggds-field">
    <label className="ggds-label" htmlFor="state-empty">Empty</label>
    <input className="ggds-input ggds-input--width-medium" id="state-empty" name="stateEmpty" type="text" />
  </div>
  <div className="ggds-field">
    <label className="ggds-label" htmlFor="state-answered">Answered</label>
    <input className="ggds-input ggds-input--width-medium" id="state-answered" name="stateAnswered" type="text" defaultValue="Kofi Mensah" />
  </div>
  <div className="ggds-field">
    <label className="ggds-label" htmlFor="state-focus">Focus (what keyboard users see)</label>
    <input className="ggds-input ggds-input--width-medium" id="state-focus" name="stateFocus" type="text" />
  </div>
  <div className="ggds-field ggds-field--error">
    <label className="ggds-label" htmlFor="state-error">Error</label>
    <p className="ggds-error-message" id="state-error-message"><span className="ggds-visually-hidden">Error:</span> Enter your full name</p>
    <input className="ggds-input ggds-input--width-medium" id="state-error" name="stateError" type="text" aria-invalid="true" aria-describedby="state-error-message" />
  </div>
</>

Example: Prefix and suffix: an amount in cedis, a weight

Open this example on its own page

HTML code for “Prefix and suffix: an amount in cedis, a weight”
HTML
<div class="ggds-field">
  <label class="ggds-label" for="amount">How much do you want to pay, in Ghana cedis?</label>
  <p class="ggds-hint" id="amount-hint">For example, 150.00</p>
  <div class="ggds-input-wrapper">
    <span class="ggds-input__prefix" aria-hidden="true">GH₵</span>
    <input class="ggds-input ggds-input--width-short" id="amount" name="amount" type="text" inputmode="decimal" spellcheck="false" aria-describedby="amount-hint">
  </div>
</div>
<div class="ggds-field">
  <label class="ggds-label" for="catch">Weight of the catch, in kilograms</label>
  <div class="ggds-input-wrapper">
    <input class="ggds-input ggds-input--width-short" id="catch" name="catch" type="text" inputmode="decimal" spellcheck="false">
    <span class="ggds-input__suffix" aria-hidden="true">kg</span>
  </div>
</div>
JSX (React)
<>
  <div className="ggds-field">
    <label className="ggds-label" htmlFor="amount">How much do you want to pay, in Ghana cedis?</label>
    <p className="ggds-hint" id="amount-hint">For example, 150.00</p>
    <div className="ggds-input-wrapper">
      <span className="ggds-input__prefix" aria-hidden="true">GH₵</span>
      <input className="ggds-input ggds-input--width-short" id="amount" name="amount" type="text" inputMode="decimal" spellCheck="false" aria-describedby="amount-hint" />
    </div>
  </div>
  <div className="ggds-field">
    <label className="ggds-label" htmlFor="catch">Weight of the catch, in kilograms</label>
    <div className="ggds-input-wrapper">
      <input className="ggds-input ggds-input--width-short" id="catch" name="catch" type="text" inputMode="decimal" spellCheck="false" />
      <span className="ggds-input__suffix" aria-hidden="true">kg</span>
    </div>
  </div>
</>

Use it

Stylesheet
ggds.css includes it. To load only the parts you use: core.css, then components/field.css (1.0 KB with gzip, minified), which also holds text inputs, radios and checkboxes.
JavaScript
None needed.

HTML

Copy the HTML under each example above. It works in any website.

Astro

No Astro component: copy the HTML.

React and Next.js

With @ggds/react:

JavaScript
import { TextInput, Textarea, Select } from '@ggds/react';

<TextInput id="phone" name="phone" type="tel" label="Mobile phone number"
  hint="For example, 024 123 4567" width="medium" autoComplete="tel"
  error={errors.phone} />   {/* the error message, aria-invalid and aria-describedby follow */}

Django

With ggds-django ({% load ggds %}):

Text
{# With FORM_RENDERER = "ggds_django.forms.GGDSFormRenderer" #}
{{ form }}
{# or one field #}
{{ form.phone.as_field_group }}

Classes and states

Classes for text input, textarea, select and file upload
ClassWhat it does
.ggds-fieldOne question: label, hint, error message and control.
.ggds-field--errorThe question has an error: a red line down its left side.
.ggds-labelThe visible label.
.ggds-label--pageA label that is also the page's heading: put the label inside an <h1>.
.ggds-hintExtra help under the label.
.ggds-error-messageWhat went wrong and how to fix it. Starts with a hidden "Error:".
.ggds-inputA text input, at least 16px text and 44px tall.
.ggds-input--width-shortFor short answers such as a code.
.ggds-input--width-mediumFor medium answers such as a phone number.
.ggds-input--width-longFor long answers such as a name or email.
.ggds-textareaA box for longer answers.
.ggds-selectA drop-down list.
.ggds-file-uploadA file input.
.ggds-input-wrapperAround an input with a prefix or suffix.
.ggds-input__prefixA unit before the answer, such as GH₵. Hidden from screen readers: say the unit in the label too.
.ggds-input__suffixA unit after the answer, such as kg. Hidden from screen readers: say the unit in the label too.
States of text input, textarea, select and file upload
StateWhat it does
:focus-visibleThe gold focus ring, and a dark border.
aria-invalid="true"The answer has an error: a red border.

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: “after a failed submit the error summary is read first, and its links reach each field”

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 text input, textarea, select and file upload
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 text input, textarea, select and file upload, 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.2.0New: ggds-label--page, for a question that is also the page's heading: <h1><label class="ggds-label ggds-label--page">.
0.1.0New: ggds-django, for Django and Django-based CMSs such as Wagtail: the page parts as template tags, a form renderer that turns any Django form into GGDS markup with an error summary and accessible errors, and the GGDS styles, themes and script as static files.
0.1.0Added.

Every change, in What’s new

  • Radios and checkboxes

    Let people choose one option (radios) or several (checkboxes) from a short list.

  • Error summary

    A box at the top of the page that lists every problem after a form is submitted.

  • Button

    Buttons do things: submit a form, save, continue.

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.