Components

Error summary

Use this component at the top of a page to summarise any errors a user has made.

When a user makes an error, you must show both an error summary and an error message next to each field that contains an error.

<div class="govuk-error-summary" aria-labelledby="error-summary-title" role="alert" tabindex="-1" data-module="error-summary">
  <h2 class="govuk-error-summary__title" id="error-summary-title">
    There is a problem
  </h2>
  <div class="govuk-error-summary__body">
    <ul class="govuk-list govuk-error-summary__list">
      <li>
        <a href="#dob-error">Date of birth must be in the past</a>
      </li>
      <li>
        <a href="#postcode-error">Enter a postcode, like AA1 1AA</a>
      </li>
    </ul>
  </div>
</div>
{% from "error-summary/macro.njk" import govukErrorSummary %}

{{ govukErrorSummary({
  titleText: "There is a problem",
  errorList: [
    {
      text: "Date of birth must be in the past",
      href: "#dob-error"
    },
    {
      text: "Enter a postcode, like AA1 1AA",
      href: "#postcode-error"
    }
  ]
}) }}

You can configure this component using the Nunjucks macro arguments.

When to use this component

Always show an error summary when there is a validation error, even if there’s only one.

How it works

You must:

  • add ‘Error: ’ to the beginning of the <title> so screen readers read it out as soon as possible
  • show an error summary at the top of a page
  • move keyboard focus to the error summary
  • include the heading ‘There is a problem’
  • link to each of the validation errors
  • show the same error messages next to the inputs with errors

Read guidance on writing good error messages.

There are 2 ways to use the error summary component. You can use HTML or, if you are using Nunjucks or the GOV.UK Prototype Kit, you can use the Nunjucks macro.

<div class="govuk-error-summary" aria-labelledby="error-summary-title" role="alert" tabindex="-1" data-module="error-summary">
  <h2 class="govuk-error-summary__title" id="error-summary-title">
    There is a problem
  </h2>
  <div class="govuk-error-summary__body">
    <ul class="govuk-list govuk-error-summary__list">
      <li>
        <a href="#dob-error">Date of birth must be in the past</a>
      </li>
      <li>
        <a href="#postcode-error">Enter a postcode, like AA1 1AA</a>
      </li>
    </ul>
  </div>
</div>
{% from "error-summary/macro.njk" import govukErrorSummary %}

{{ govukErrorSummary({
  titleText: "There is a problem",
  errorList: [
    {
      text: "Date of birth must be in the past",
      href: "#dob-error"
    },
    {
      text: "Enter a postcode, like AA1 1AA",
      href: "#postcode-error"
    }
  ]
}) }}

You can configure this component using the Nunjucks macro arguments.

Research on this component

If you’ve used this component, get in touch to share your user research findings.

Get in touch

If you’ve got a question, idea or suggestion share it in #govuk-design-system on cross-government Slack (open in app) or email the Design System team on govuk-design-system-support@digital.cabinet-office.gov.uk

Discuss ‘Error summary’ on GitHub