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

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

Open this example on its own page

HTML code for “Radios”
HTML
<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>
JSX (React)
<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

Open this example on its own page

HTML code for “Checkboxes”
HTML
<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>
JSX (React)
<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

Open this example on its own page

HTML code for “Radios with an error”
HTML
<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>
JSX (React)
<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

Open this example on its own page

HTML code for “States: not chosen, chosen and focus”
HTML
<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>
JSX (React)
<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.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 { 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 %}):

Text
{# RadioSelect and CheckboxSelectMultiple widgets, with GGDSFormRenderer #}
{{ form.contact_method.as_field_group }}

Classes and states

Classes for radios and checkboxes
ClassWhat it does
.ggds-fieldsetThe <fieldset> that groups the options.
.ggds-fieldset__legendThe question, in the <legend>.
.ggds-fieldset__legend--pageA question that is also the page heading: set as large as an h1.
.ggds-choicesThe list of options, one under another.
.ggds-choices--inlineOptions side by side, for two short ones such as Yes and No.
.ggds-choiceOne option: the whole row can be tapped.
.ggds-choice__inputThe radio or checkbox, enlarged.
.ggds-choice__labelThe option's label.
.ggds-choice__hintExtra help for one option.
States of radios and checkboxes
StateWhat it does
:checkedChosen.
:focus-visibleThe gold focus ring.
aria-invalid="true" and .ggds-field--errorThe 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.

Manual accessibility checks for radios and checkboxes
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 radios and checkboxes, newest first
VersionChange
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

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.