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

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

Open this example on its own page

HTML code for “Cookie banner”
HTML
<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>
JSX (React)
<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

Open this example on its own page

HTML code for “After a choice”
HTML
<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>
JSX (React)
<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.css includes it. To load only the parts you use: core.css, then components/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:

JavaScript
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 %}):

Django template
{% ggds_cookie_banner "Example Agency" action="/cookies/" choice=choice %}

Classes and states

Classes for cookie banner
ClassWhat it does
.ggds-cookie-bannerThe question about cookies, at the top of the page.
.ggds-cookie-banner__innerThe content, at the page width.
.ggds-cookie-banner__titleThe heading.
.ggds-cookie-banner__bodyWhat the website uses cookies for, or the choice the person made.
.ggds-cookie-banner__actionsA 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.

Manual accessibility checks for cookie banner
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 cookie banner, newest first
VersionChange
0.4.0New 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.0Added.

Every change, in What’s new

  • Government website banner

    Tells people the website belongs to the Government of Ghana, and how to check.

  • Button

    Buttons do things: submit a form, save, continue.

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.