Forms
Button
Buttons do things: submit a form, save, continue.
When to use
- For actions.
When not to use
- For links to other pages, except one link that starts a task ("Start now").
How to use
- Use one main (primary) button per page. Use secondary and quiet buttons for other actions, and the warning style only for actions that delete something.
Do
- Say what will happen: "Send complaint".
Don't
- Write "Submit" or "Click here".
- Put two primary buttons side by side.
Accessibility
What GGDS does
- Buttons are at least 44px tall, with the gold focus ring.
- The main button's white text is measured against the contrast minimum every time GGDS is built.
What you need to do
- Use a
<button>for actions and a link for going somewhere else. - Write what will happen: "Send complaint", not "Submit".
- Avoid disabled buttons: people cannot find out why they cannot continue. Let them try, and explain what to fix.
Example: Button variants
<div class="ggds-button-group">
<button class="ggds-button" type="button">Continue</button>
<button class="ggds-button ggds-button--secondary" type="button">Save as draft</button>
<button class="ggds-button ggds-button--quiet" type="button">Cancel</button>
<button class="ggds-button ggds-button--warning" type="button">Withdraw application</button>
</div><div className="ggds-button-group">
<button className="ggds-button" type="button">Continue</button>
<button className="ggds-button ggds-button--secondary" type="button">Save as draft</button>
<button className="ggds-button ggds-button--quiet" type="button">Cancel</button>
<button className="ggds-button ggds-button--warning" type="button">Withdraw application</button>
</div>Example: Link styled as a button (navigation)
<a class="ggds-button" href="/services/licence/apply/">Start now</a><a className="ggds-button" href="/services/licence/apply/">Start now</a>Example: States: normal, focus and disabled
<div class="ggds-button-group">
<button class="ggds-button" type="button">Continue</button>
<button class="ggds-button ggds-button--secondary" type="button">Save as draft</button>
<button class="ggds-button ggds-button--quiet" type="button">Cancel</button>
<button class="ggds-button ggds-button--warning" type="button">Withdraw application</button>
</div>
<div class="ggds-button-group">
<button class="ggds-button" type="button">Continue</button>
<button class="ggds-button ggds-button--secondary" type="button">Save as draft</button>
<button class="ggds-button ggds-button--quiet" type="button">Cancel</button>
<button class="ggds-button ggds-button--warning" type="button">Withdraw application</button>
</div>
<div class="ggds-button-group">
<button class="ggds-button" type="button" disabled>Continue</button>
<button class="ggds-button ggds-button--secondary" type="button" aria-disabled="true">Save as draft</button>
</div><>
<div className="ggds-button-group">
<button className="ggds-button" type="button">Continue</button>
<button className="ggds-button ggds-button--secondary" type="button">Save as draft</button>
<button className="ggds-button ggds-button--quiet" type="button">Cancel</button>
<button className="ggds-button ggds-button--warning" type="button">Withdraw application</button>
</div>
<div className="ggds-button-group">
<button className="ggds-button" type="button">Continue</button>
<button className="ggds-button ggds-button--secondary" type="button">Save as draft</button>
<button className="ggds-button ggds-button--quiet" type="button">Cancel</button>
<button className="ggds-button ggds-button--warning" type="button">Withdraw application</button>
</div>
<div className="ggds-button-group">
<button className="ggds-button" type="button" disabled>Continue</button>
<button className="ggds-button ggds-button--secondary" type="button" aria-disabled="true">Save as draft</button>
</div>
</>Use it
- Stylesheet
ggds.cssincludes it. To load only the parts you use:core.css, thencomponents/button.css(0.6 KB with gzip, minified).- 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 { Button, ButtonGroup } from '@ggds/react';
<ButtonGroup>
<Button type="submit">Continue</Button>
<Button variant="secondary">Save as draft</Button>
</ButtonGroup>
<Button href="/services/licence/apply/">Start now</Button>Django
No template tag: copy the HTML into your template.
Classes and states
| Class | What it does |
|---|---|
.ggds-button | The main (primary) button: one per page. |
.ggds-button--secondary | For other actions, such as saving a draft. |
.ggds-button--quiet | Looks like a link: for minor actions such as Cancel. |
.ggds-button--warning | Only for actions that delete or withdraw something. |
.ggds-button-group | Buttons side by side, wrapping on narrow screens. |
| State | What it does |
|---|---|
:hover | A darker background. |
:focus-visible | The gold focus ring. |
:disabled, aria-disabled="true" | Faded, with a not-allowed cursor. Prefer explaining why an action is not available. |
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
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.3.0 | Button group: space below it, like a form field, so a heading or text after the buttons is not cramped. |
| 0.1.0 | Added. |
Related components
Something wrong, unclear or missing? or suggest a change to it on GitHub. You need a GitHub account.