Forms
Radios and checkboxes
Let people choose one option (radios) or several (checkboxes) from a short list.
When to use
- For up to about eight options.
When not to use
- For long lists. Use a select field.
- For a single yes/no agreement that could be a button.
How to use
- Group the options in a
<fieldset>with the question in its<legend>. - On error, put the message after the question and connect it with
aria-describedby. - In the error summary, link to the first option.
Accessibility
What GGDS does
- The radios and checkboxes are enlarged, and the whole row can be tapped.
- They are the browser's own inputs, so they work with every assistive technology.
What you need to do
- Group the options in a
<fieldset>with the question in its<legend>. - On error, put the message after the question, connect it with
aria-describedby, and link the error summary to the first option.
Example: Radios
<div class="ggds-field">
<fieldset class="ggds-fieldset" aria-describedby="contact-hint">
<legend class="ggds-fieldset__legend">How should we contact you?</legend>
<p class="ggds-hint" id="contact-hint">Choose one</p>
<div class="ggds-choices">
<div class="ggds-choice">
<input class="ggds-choice__input" id="contact-call" name="contact" type="radio" value="call">
<label class="ggds-choice__label" for="contact-call">Phone call</label>
</div>
<div class="ggds-choice">
<input class="ggds-choice__input" id="contact-sms" name="contact" type="radio" value="sms">
<label class="ggds-choice__label" for="contact-sms">SMS</label>
</div>
<div class="ggds-choice">
<input class="ggds-choice__input" id="contact-email" name="contact" type="radio" value="email" aria-describedby="contact-email-hint">
<label class="ggds-choice__label" for="contact-email">Email <span class="ggds-choice__hint" id="contact-email-hint">We reply within 5 working days</span></label>
</div>
</div>
</fieldset>
</div><div className="ggds-field">
<fieldset className="ggds-fieldset" aria-describedby="contact-hint">
<legend className="ggds-fieldset__legend">How should we contact you?</legend>
<p className="ggds-hint" id="contact-hint">Choose one</p>
<div className="ggds-choices">
<div className="ggds-choice">
<input className="ggds-choice__input" id="contact-call" name="contact" type="radio" value="call" />
<label className="ggds-choice__label" htmlFor="contact-call">Phone call</label>
</div>
<div className="ggds-choice">
<input className="ggds-choice__input" id="contact-sms" name="contact" type="radio" value="sms" />
<label className="ggds-choice__label" htmlFor="contact-sms">SMS</label>
</div>
<div className="ggds-choice">
<input className="ggds-choice__input" id="contact-email" name="contact" type="radio" value="email" aria-describedby="contact-email-hint" />
<label className="ggds-choice__label" htmlFor="contact-email">Email <span className="ggds-choice__hint" id="contact-email-hint">We reply within 5 working days</span></label>
</div>
</div>
</fieldset>
</div>Example: Checkboxes
<div class="ggds-field">
<fieldset class="ggds-fieldset" aria-describedby="services-hint">
<legend class="ggds-fieldset__legend">Which services does your business offer?</legend>
<p class="ggds-hint" id="services-hint">Select all that apply</p>
<div class="ggds-choices">
<div class="ggds-choice">
<input class="ggds-choice__input" id="services-internet" name="services" type="checkbox" value="internet">
<label class="ggds-choice__label" for="services-internet">Internet access</label>
</div>
<div class="ggds-choice">
<input class="ggds-choice__input" id="services-voice" name="services" type="checkbox" value="voice">
<label class="ggds-choice__label" for="services-voice">Voice calls</label>
</div>
<div class="ggds-choice">
<input class="ggds-choice__input" id="services-broadcast" name="services" type="checkbox" value="broadcast">
<label class="ggds-choice__label" for="services-broadcast">Broadcasting</label>
</div>
</div>
</fieldset>
</div><div className="ggds-field">
<fieldset className="ggds-fieldset" aria-describedby="services-hint">
<legend className="ggds-fieldset__legend">Which services does your business offer?</legend>
<p className="ggds-hint" id="services-hint">Select all that apply</p>
<div className="ggds-choices">
<div className="ggds-choice">
<input className="ggds-choice__input" id="services-internet" name="services" type="checkbox" value="internet" />
<label className="ggds-choice__label" htmlFor="services-internet">Internet access</label>
</div>
<div className="ggds-choice">
<input className="ggds-choice__input" id="services-voice" name="services" type="checkbox" value="voice" />
<label className="ggds-choice__label" htmlFor="services-voice">Voice calls</label>
</div>
<div className="ggds-choice">
<input className="ggds-choice__input" id="services-broadcast" name="services" type="checkbox" value="broadcast" />
<label className="ggds-choice__label" htmlFor="services-broadcast">Broadcasting</label>
</div>
</div>
</fieldset>
</div>Example: Radios with an error
<div class="ggds-field ggds-field--error">
<fieldset class="ggds-fieldset" aria-describedby="contacted-error">
<legend class="ggds-fieldset__legend">Have you contacted your provider about this problem?</legend>
<p class="ggds-error-message" id="contacted-error"><span class="ggds-visually-hidden">Error:</span> Select yes if you have contacted your provider</p>
<div class="ggds-choices ggds-choices--inline">
<div class="ggds-choice">
<input class="ggds-choice__input" id="contacted-yes" name="contacted" type="radio" value="yes">
<label class="ggds-choice__label" for="contacted-yes">Yes</label>
</div>
<div class="ggds-choice">
<input class="ggds-choice__input" id="contacted-no" name="contacted" type="radio" value="no">
<label class="ggds-choice__label" for="contacted-no">No</label>
</div>
</div>
</fieldset>
</div><div className="ggds-field ggds-field--error">
<fieldset className="ggds-fieldset" aria-describedby="contacted-error">
<legend className="ggds-fieldset__legend">Have you contacted your provider about this problem?</legend>
<p className="ggds-error-message" id="contacted-error"><span className="ggds-visually-hidden">Error:</span> Select yes if you have contacted your provider</p>
<div className="ggds-choices ggds-choices--inline">
<div className="ggds-choice">
<input className="ggds-choice__input" id="contacted-yes" name="contacted" type="radio" value="yes" />
<label className="ggds-choice__label" htmlFor="contacted-yes">Yes</label>
</div>
<div className="ggds-choice">
<input className="ggds-choice__input" id="contacted-no" name="contacted" type="radio" value="no" />
<label className="ggds-choice__label" htmlFor="contacted-no">No</label>
</div>
</div>
</fieldset>
</div>Example: States: not chosen, chosen and focus
<div class="ggds-field">
<fieldset class="ggds-fieldset">
<legend class="ggds-fieldset__legend">Which updates do you want?</legend>
<div class="ggds-choices">
<div class="ggds-choice">
<input class="ggds-choice__input" id="updates-news" name="updates" type="checkbox" value="news">
<label class="ggds-choice__label" for="updates-news">News (not chosen)</label>
</div>
<div class="ggds-choice">
<input class="ggds-choice__input" id="updates-fees" name="updates" type="checkbox" value="fees" checked>
<label class="ggds-choice__label" for="updates-fees">Fee changes (chosen)</label>
</div>
<div class="ggds-choice">
<input class="ggds-choice__input" id="updates-jobs" name="updates" type="checkbox" value="jobs">
<label class="ggds-choice__label" for="updates-jobs">Jobs (focus: what keyboard users see)</label>
</div>
</div>
</fieldset>
</div><div className="ggds-field">
<fieldset className="ggds-fieldset">
<legend className="ggds-fieldset__legend">Which updates do you want?</legend>
<div className="ggds-choices">
<div className="ggds-choice">
<input className="ggds-choice__input" id="updates-news" name="updates" type="checkbox" value="news" />
<label className="ggds-choice__label" htmlFor="updates-news">News (not chosen)</label>
</div>
<div className="ggds-choice">
<input className="ggds-choice__input" id="updates-fees" name="updates" type="checkbox" value="fees" defaultChecked />
<label className="ggds-choice__label" htmlFor="updates-fees">Fee changes (chosen)</label>
</div>
<div className="ggds-choice">
<input className="ggds-choice__input" id="updates-jobs" name="updates" type="checkbox" value="jobs" />
<label className="ggds-choice__label" htmlFor="updates-jobs">Jobs (focus: what keyboard users see)</label>
</div>
</div>
</fieldset>
</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 { Radios, Checkboxes } from '@ggds/react';
<Radios name="reply" legend="How should we reply?" error={errors.reply}
items={[{ value: 'sms', label: 'SMS' }, { value: 'email', label: 'Email' }]} />Django
With ggds-django ({% load ggds %}):
{# RadioSelect and CheckboxSelectMultiple widgets, with GGDSFormRenderer #}
{{ form.contact_method.as_field_group }}Classes and states
| Class | What it does |
|---|---|
.ggds-fieldset | The <fieldset> that groups the options. |
.ggds-fieldset__legend | The question, in the <legend>. |
.ggds-fieldset__legend--page | A question that is also the page heading: set as large as an h1. |
.ggds-choices | The list of options, one under another. |
.ggds-choices--inline | Options side by side, for two short ones such as Yes and No. |
.ggds-choice | One option: the whole row can be tapped. |
.ggds-choice__input | The radio or checkbox, enlarged. |
.ggds-choice__label | The option's label. |
.ggds-choice__hint | Extra help for one option. |
| State | What it does |
|---|---|
:checked | Chosen. |
:focus-visible | The gold focus ring. |
aria-invalid="true" and .ggds-field--error | The question has an error, as for text inputs. |
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.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.