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

Error summary

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

When to use

  • After someone submits a form with problems.

When not to use

  • Before someone has submitted the form.
  • For messages that are not errors. Use a notice.

How to use

  • Use the same words as the message next to each field.
  • Link each item to its field.
  • Start the page title with "Error: " while it shows.
  • Add data-ggds-module="error-summary": with the GGDS script, the page moves to the summary when it loads.

Accessibility

What GGDS does

  • It has role="alert", so screen readers announce it even without JavaScript.
  • With the GGDS script it takes focus when the page loads, and each link moves focus to its field with the question in view.

What you need to do

  • List every error, in the same words as the message next to each field, and link each one to its field.
  • Start the page <title> with "Error: " while it shows.
  • Put it at the top of the main content, before the form.

Example: Form after a failed submit

Open this example on its own page

HTML code for “Form after a failed submit”
HTML
<div class="ggds-error-summary" data-ggds-module="error-summary" role="alert" aria-labelledby="error-summary-title" tabindex="-1">
  <h2 class="ggds-error-summary__title" id="error-summary-title">There is a problem</h2>
  <ul class="ggds-error-summary__list">
    <li><a href="#name">Enter your full name</a></li>
    <li><a href="#reply-sms">Select how we should reply</a></li>
  </ul>
</div>
<h1>Report a problem</h1>
<form action="./" method="post" novalidate>
  <div class="ggds-field ggds-field--error">
    <label class="ggds-label" for="name">Full name</label>
    <p class="ggds-error-message" id="name-error"><span class="ggds-visually-hidden">Error:</span> Enter your full name</p>
    <input class="ggds-input ggds-input--width-long" id="name" name="name" type="text" autocomplete="name" aria-invalid="true" aria-describedby="name-error">
  </div>
  <div class="ggds-field ggds-field--error">
    <fieldset class="ggds-fieldset" aria-describedby="reply-error">
      <legend class="ggds-fieldset__legend">How should we reply?</legend>
      <p class="ggds-error-message" id="reply-error"><span class="ggds-visually-hidden">Error:</span> Select how we should reply</p>
      <div class="ggds-choices">
        <div class="ggds-choice">
          <input class="ggds-choice__input" id="reply-sms" name="reply" type="radio" value="sms">
          <label class="ggds-choice__label" for="reply-sms">SMS</label>
        </div>
        <div class="ggds-choice">
          <input class="ggds-choice__input" id="reply-email" name="reply" type="radio" value="email">
          <label class="ggds-choice__label" for="reply-email">Email</label>
        </div>
      </div>
    </fieldset>
  </div>
  <button class="ggds-button" type="submit">Send report</button>
</form>
JSX (React)
<>
  <div className="ggds-error-summary" data-ggds-module="error-summary" role="alert" aria-labelledby="error-summary-title" tabIndex={-1}>
    <h2 className="ggds-error-summary__title" id="error-summary-title">There is a problem</h2>
    <ul className="ggds-error-summary__list">
      <li><a href="#name">Enter your full name</a></li>
      <li><a href="#reply-sms">Select how we should reply</a></li>
    </ul>
  </div>
  <h1>Report a problem</h1>
  <form action="./" method="post" noValidate>
    <div className="ggds-field ggds-field--error">
      <label className="ggds-label" htmlFor="name">Full name</label>
      <p className="ggds-error-message" id="name-error"><span className="ggds-visually-hidden">Error:</span> Enter your full name</p>
      <input className="ggds-input ggds-input--width-long" id="name" name="name" type="text" autoComplete="name" aria-invalid="true" aria-describedby="name-error" />
    </div>
    <div className="ggds-field ggds-field--error">
      <fieldset className="ggds-fieldset" aria-describedby="reply-error">
        <legend className="ggds-fieldset__legend">How should we reply?</legend>
        <p className="ggds-error-message" id="reply-error"><span className="ggds-visually-hidden">Error:</span> Select how we should reply</p>
        <div className="ggds-choices">
          <div className="ggds-choice">
            <input className="ggds-choice__input" id="reply-sms" name="reply" type="radio" value="sms" />
            <label className="ggds-choice__label" htmlFor="reply-sms">SMS</label>
          </div>
          <div className="ggds-choice">
            <input className="ggds-choice__input" id="reply-email" name="reply" type="radio" value="email" />
            <label className="ggds-choice__label" htmlFor="reply-email">Email</label>
          </div>
        </div>
      </fieldset>
    </div>
    <button className="ggds-button" type="submit">Send report</button>
  </form>
</>

Use it

Stylesheet
ggds.css includes it. To load only the parts you use: core.css, then components/error-summary.css (0.3 KB with gzip, minified).
JavaScript
Optional. With data-ggds-module="error-summary", the GGDS script moves focus to the summary when the page loads, and each link moves focus to its field and scrolls its label or question into view.

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 { ErrorSummary } from '@ggds/react';

{/* First in <main>. It takes the focus when errors appear; nothing shows without errors. */}
<ErrorSummary errors={[{ href: '#phone', text: 'Enter your mobile phone number' }]} />

Django

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

Text
{# Automatic with {{ form }} and GGDSFormRenderer; on its own: #}
{% ggds_error_summary form %}

Classes and states

Classes for error summary
ClassWhat it does
.ggds-error-summaryThe box, with a thick red border. Give it role="alert", aria-labelledby (its title) and tabindex="-1".
.ggds-error-summary__title"There is a problem".
.ggds-error-summary__listOne link per problem, each to its field.
States of error summary
StateWhat it does
:focusFocused when the page loads (with the GGDS script).

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: “error summary takes focus on load”
  • 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 error summary
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 error summary, newest first
VersionChange
0.4.0React and Astro: the banner's register link and the hero's search label now default to GGDS's own words, so you no longer have to pass them. React has errorTitle() for the page title while a form has errors.
0.1.0The error summary no longer scrolls the page around it when shown inside a frame.
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.