Page structure
Cookie banner
Asks people before setting cookies the website does not need to work, such as analytics, and remembers their choice.
When to use
- Only when the website wants to set cookies it does not need to work, such as analytics or video from another website.
When not to use
- When the website uses only essential cookies, such as to remember a form's answers or keep people signed in. The best government website needs no cookie banner: measure visits on the server, without cookies, where you can.
How to use
- Put it first in
<body>, before the skip link, on every page until the person chooses. - Set no analytics cookie, and load no analytics, until the person accepts.
- Give both choices the same button style and the same place, so neither is easier to press. Rejecting must be as easy as accepting.
- The buttons send a form to your website, which remembers the choice in an essential cookie and shows the page again with the confirmation, then nothing once people hide it. No JavaScript is needed.
- Link "View cookies" to a page that lists every cookie, what it is for and how long it lasts, where people can change their choice at any time.
- Follow the Data Protection Act, 2012 (Act 843) and any guidance from the Data Protection Commission.
Accessibility
What GGDS does
- It is a named region with a heading, so screen reader users know what it is.
- It sits in the page, not over it: it never hides the content or traps the keyboard.
What you need to do
- After a choice, show the confirmation in the same place, so people know it worked.
- Do not move focus into the banner when the page loads.
Example: Cookie banner
<div class="ggds-cookie-banner" role="region" aria-label="Cookies on Example Agency">
<div class="ggds-container ggds-cookie-banner__inner">
<h2 class="ggds-cookie-banner__title">Cookies on Example Agency</h2>
<div class="ggds-cookie-banner__body">
<p>We use some essential cookies to make this website work.</p>
<p>We would also like to use analytics cookies to understand how you use the website, so we can improve it.</p>
</div>
<form class="ggds-cookie-banner__actions" method="post" action="/cookies/">
<button class="ggds-button" type="submit" name="cookies" value="accept">Accept analytics cookies</button>
<button class="ggds-button" type="submit" name="cookies" value="reject">Reject analytics cookies</button>
<a href="/cookies/">View cookies</a>
</form>
</div>
</div><div className="ggds-cookie-banner" role="region" aria-label="Cookies on Example Agency">
<div className="ggds-container ggds-cookie-banner__inner">
<h2 className="ggds-cookie-banner__title">Cookies on Example Agency</h2>
<div className="ggds-cookie-banner__body">
<p>We use some essential cookies to make this website work.</p>
<p>We would also like to use analytics cookies to understand how you use the website, so we can improve it.</p>
</div>
<form className="ggds-cookie-banner__actions" method="post" action="/cookies/">
<button className="ggds-button" type="submit" name="cookies" value="accept">Accept analytics cookies</button>
<button className="ggds-button" type="submit" name="cookies" value="reject">Reject analytics cookies</button>
<a href="/cookies/">View cookies</a>
</form>
</div>
</div>Example: After a choice
<div class="ggds-cookie-banner" role="region" aria-label="Cookies on Example Agency">
<div class="ggds-container ggds-cookie-banner__inner">
<div class="ggds-cookie-banner__body">
<p>You have accepted analytics cookies. You can <a href="/cookies/">change your cookie settings</a> at any time.</p>
</div>
<form class="ggds-cookie-banner__actions" method="post" action="/cookies/">
<button class="ggds-button ggds-button--secondary" type="submit" name="cookies" value="hide">Hide cookie message</button>
</form>
</div>
</div><div className="ggds-cookie-banner" role="region" aria-label="Cookies on Example Agency">
<div className="ggds-container ggds-cookie-banner__inner">
<div className="ggds-cookie-banner__body">
<p>You have accepted analytics cookies. You can <a href="/cookies/">change your cookie settings</a> at any time.</p>
</div>
<form className="ggds-cookie-banner__actions" method="post" action="/cookies/">
<button className="ggds-button ggds-button--secondary" type="submit" name="cookies" value="hide">Hide cookie message</button>
</form>
</div>
</div>Use it
- Stylesheet
ggds.cssincludes it. To load only the parts you use:core.css, thencomponents/cookie-banner.css(0.3 KB with gzip, minified).- JavaScript
- None needed.
HTML
Copy the HTML under each example above. It works in any website.
Astro
With @ggds/astro:
import CookieBanner from '@ggds/astro/CookieBanner.astro';
<CookieBanner service="Example Agency" action="/cookies/" />React and Next.js
No React component: switch the HTML under an example to JSX (React) and copy it.
Django
With ggds-django ({% load ggds %}):
{% ggds_cookie_banner "Example Agency" action="/cookies/" choice=choice %}Classes and states
| Class | What it does |
|---|---|
.ggds-cookie-banner | The question about cookies, at the top of the page. |
.ggds-cookie-banner__inner | The content, at the page width. |
.ggds-cookie-banner__title | The heading. |
.ggds-cookie-banner__body | What the website uses cookies for, or the choice the person made. |
.ggds-cookie-banner__actions | A form: the two choices, equally prominent, and a link to the cookies 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: “the cookie banner offers both choices equally, without JavaScript”
- Behaviour test: “no horizontal scrolling at 320px”
- Behaviour test: “no horizontal scrolling at 320px with a wide font”
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: back link, side navigation, contents list ("On this page"), language switcher, phase banner, cookie banner and character count, in HTML, Django, React and (except the character count) Astro. All are alpha: tested automatically, not yet on a live website. The cookie banner needs no JavaScript: its buttons send a form, and both choices look the same. |
| 0.1.0 | Added. |
Related components
Something wrong, unclear or missing? or suggest a change to it on GitHub. You need a GitHub account.