Forms
Dialog
A box over the page that asks people to confirm something before it happens, such as deleting a draft.
When to use
- To confirm an action that cannot be undone, such as deleting a draft application or withdrawing one.
- For the timeout warning.
When not to use
- For anything people need to read carefully, fill in or come back to: use a page.
- For messages: use a notice on the page. A dialog interrupts people, and some find it hard to use with a screen magnifier.
How to use
- Make the opener a link to a confirmation page, so it works without JavaScript, and add
data-ggds-dialog="<the dialog's id>". With the GGDS script, the link opens the dialog instead. - Use the browser's
<dialog>withclass="ggds-dialog"andaria-labelledbynaming its heading. - Ask a question as the heading ("Delete this draft?") and say what will happen. Name the action on the button ("Delete draft", not "OK"), and give a way out ("Cancel") with
data-ggds-dialog-close. - Put the action in a form that posts, inside the dialog, so the server does it, as on the confirmation page.
- Use
ggds-dialog--warningfor an action that cannot be undone.
Accessibility
What GGDS does
- The browser keeps focus inside the dialog, makes the page behind it unavailable, closes it with Escape and returns focus to the link that opened it.
- Focus starts on the first button, which is never the action that cannot be undone.
- Without JavaScript, the link opens the confirmation page.
What you need to do
- Keep it short: a heading, a sentence and two buttons.
- Put the safe choice first, so it gets focus.
Example: Confirm before deleting
<p>Draft saved on 12 November 2026.</p>
<a class="ggds-button ggds-button--warning" href="#delete-draft-page" data-ggds-dialog="delete-draft">Delete draft</a>
<dialog class="ggds-dialog ggds-dialog--warning" id="delete-draft" aria-labelledby="delete-draft-title">
<h2 class="ggds-dialog__title" id="delete-draft-title">Delete this draft?</h2>
<div class="ggds-dialog__body"><p>Your answers will be deleted. You cannot get them back.</p></div>
<form class="ggds-dialog__actions" action="#delete-draft-page" method="post">
<button class="ggds-button ggds-button--secondary" type="button" data-ggds-dialog-close>Cancel</button>
<button class="ggds-button ggds-button--warning" type="submit">Delete draft</button>
</form>
</dialog><>
<p>Draft saved on 12 November 2026.</p>
<a className="ggds-button ggds-button--warning" href="#delete-draft-page" data-ggds-dialog="delete-draft">Delete draft</a>
<dialog className="ggds-dialog ggds-dialog--warning" id="delete-draft" aria-labelledby="delete-draft-title">
<h2 className="ggds-dialog__title" id="delete-draft-title">Delete this draft?</h2>
<div className="ggds-dialog__body"><p>Your answers will be deleted. You cannot get them back.</p></div>
<form className="ggds-dialog__actions" action="#delete-draft-page" method="post">
<button className="ggds-button ggds-button--secondary" type="button" data-ggds-dialog-close>Cancel</button>
<button className="ggds-button ggds-button--warning" type="submit">Delete draft</button>
</form>
</dialog>
</>Use it
- Stylesheet
ggds.cssincludes it. To load only the parts you use:core.css, thencomponents/dialog.css(0.6 KB with gzip, minified).- JavaScript
- Needed to open it: @ggds/js turns the link into a button that opens the dialog, and closes it with data-ggds-dialog-close. Without it, the link goes to a confirmation page.
HTML
Copy the HTML under each example above. It works in any website.
Astro
With @ggds/astro:
import Dialog from '@ggds/astro/Dialog.astro';
---
import Dialog from '@ggds/astro/Dialog.astro';
---
<a class="ggds-button ggds-button--warning" href="/drafts/delete/" data-ggds-dialog="delete-draft">Delete draft</a>
<Dialog id="delete-draft" title="Delete this draft?" warning action="/drafts/delete/">
<p>Your answers will be deleted. You cannot get them back.</p>
<button slot="actions" class="ggds-button ggds-button--warning" type="submit">Delete draft</button>
</Dialog> {/* Cancel comes first */}React and Next.js
With @ggds/react:
import { Dialog, Button } from '@ggds/react';
{/* Cancel comes first, and closes it */}
<Dialog id="delete-draft" open={open} onClose={() => setOpen(false)} warning
title="Delete this draft?" action="/drafts/delete/"
actions={<Button variant="warning" type="submit">Delete draft</Button>}>
<p>Your answers will be deleted. You cannot get them back.</p>
</Dialog>Django
With ggds-django ({% load ggds %}):
{% load ggds %}
{% ggds_dialog id="delete-draft" title="Delete this draft?" body="Your answers will be deleted." action="/drafts/delete/" confirm="Delete draft" warning=True %}Classes and states
| Class | What it does |
|---|---|
.ggds-dialog | On a <dialog>: a box over the page, opened as a modal. |
.ggds-dialog--warning | For an action that cannot be undone: an orange line at the top. |
.ggds-dialog__title | The heading, named by the dialog's aria-labelledby. |
.ggds-dialog__body | What will happen. |
.ggds-dialog__actions | The buttons, the safe one first. |
| State | What it does |
|---|---|
[open] | The dialog is showing, over a darkened page. |
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: “dialog: the link opens it, Escape and Cancel close it, and focus goes back to the link”
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.1.0 | Added. |
Related components
Something wrong, unclear or missing? or suggest a change to it on GitHub. You need a GitHub account.