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
- For a choice from a short list. Use radios or checkboxes.
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:", andaria-invalid="true"on the input. Also list it in the error summary. - Use
autocompletefor 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₵) orggds-input__suffix(kg) insideggds-input-wrapper. Say the unit in the label as well ("in Ghana cedis"): the prefix and suffix are hidden from screen readers. Useinputmode="decimal", nottype="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
autocompleteto personal details, so people can fill them in quickly.
Example: Text input with hint
<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><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
<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><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
<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><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
<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><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
<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><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
<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><>
<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
<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><>
<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.cssincludes it. To load only the parts you use:core.css, thencomponents/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:
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 %}):
{# With FORM_RENDERER = "ggds_django.forms.GGDSFormRenderer" #}
{{ form }}
{# or one field #}
{{ form.phone.as_field_group }}Classes and states
| Class | What it does |
|---|---|
.ggds-field | One question: label, hint, error message and control. |
.ggds-field--error | The question has an error: a red line down its left side. |
.ggds-label | The visible label. |
.ggds-label--page | A label that is also the page's heading: put the label inside an <h1>. |
.ggds-hint | Extra help under the label. |
.ggds-error-message | What went wrong and how to fix it. Starts with a hidden "Error:". |
.ggds-input | A text input, at least 16px text and 44px tall. |
.ggds-input--width-short | For short answers such as a code. |
.ggds-input--width-medium | For medium answers such as a phone number. |
.ggds-input--width-long | For long answers such as a name or email. |
.ggds-textarea | A box for longer answers. |
.ggds-select | A drop-down list. |
.ggds-file-upload | A file input. |
.ggds-input-wrapper | Around an input with a prefix or suffix. |
.ggds-input__prefix | A unit before the answer, such as GH₵. Hidden from screen readers: say the unit in the label too. |
.ggds-input__suffix | A unit after the answer, such as kg. Hidden from screen readers: say the unit in the label too. |
| State | What it does |
|---|---|
:focus-visible | The 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.
| 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.2.0 | New: ggds-label--page, for a question that is also the page's heading: <h1><label class="ggds-label ggds-label--page">. |
| 0.1.0 | New: 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.0 | Added. |
Related components
Something wrong, unclear or missing? or suggest a change to it on GitHub. You need a GitHub account.