Preview brand Custom

Cookie banner

A consent banner for sites that use analytics which set cookies. Nothing loads until the visitor says yes.

Beta

What it looks like

The real banner, drawn in place rather than pinned to the bottom of the screen, in whichever brand you're previewing. It's a preview: the buttons don't do anything and nothing is stored.

Preview only: Accept all and Reject all do nothing here.

When to use it

  • The site uses analytics that set cookies, such as Google Analytics.
  • Setting analytics.ga in a site's config brings it, with Cookie settings in the footer.

Use something else when:

  • The analytics set no cookies (Umami): there is nothing to ask, so no banner.
  • You want to tell visitors something else: the site message, a notice.

On this site

mediadreams.co.uk counts visits two ways. Umami sets no cookies and needs no consent. Google Analytics does set cookies, so since 4 November 2026 this site shows the banner on a first visit, and loads nothing from Google unless the answer is Accept all. Cookie settings in the footer brings it back.

Using it on a site

Set analytics.ga in the site's config to its GA4 Measurement ID: the page layout adds the banner, and the footer gets Cookie settings. The component's own settings, for a layout that places it by hand:

astro
---
import CookieBanner from '../components/CookieBanner.astro';
---
<!-- In the site's layout, once, just before </body> -->
<CookieBanner measurementId="G-XXXXXXXXXX" />

<!-- Optional settings -->
<CookieBanner
  measurementId="G-XXXXXXXXXX"
  analyticsName="Google Analytics"
  policyHref="/cookie-policy/"
  storageKey="cookie-consent"
/>

<!-- A "Cookie settings" link anywhere on the site -->
<button type="button" onclick="reopenCookiePreferences()">Cookie settings</button>
SettingDefaultWhat it does
measurementIdnoneThe client's GA4 Measurement ID (G- then letters and numbers). The build stops if it isn't in that form. Without one, the banner works but accepting loads nothing.
analyticsNameGoogle AnalyticsHow the analytics tool is named in the banner text.
policyHref/legal/cookies/The client's cookie policy page.
storageKeycookie-consentWhere the visitor's choice is kept in their browser, with when it was made.
maxAgeDays365How long a choice stands before the banner asks again.
previewoffDraws the banner inline and inert, for documentation like this page.

If the site has a Content Security Policy, allow https://www.googletagmanager.com and Google Analytics' collection addresses, or the script is blocked after the visitor accepts. The cookie policy should name the analytics cookies and say how long they last.

How it works

  • Nothing that sets a cookie loads until the visitor says yes.
  • "Accept all" and "Reject all" are equal: same style, same size, one click each, as the UK regulator (ICO) expects.
  • The choice is remembered, and the component provides a way to reopen it: link a "Cookie settings" option to it so visitors can change their mind. The header's settings menu, the footer and holding pages' footers already do. A choice is asked for again after 12 months.
  • It is drawn at the foot of the window and comes first in the page for the keyboard and screen readers, straight after the skip link. It never traps keyboard focus, and it's hidden in print.
  • Asked for again from Cookie settings, it takes the focus; once a choice is made the focus goes back to Cookie settings.

Accessibility

What it does for you

  • A region named "Cookie notice". It is drawn at the foot of the window and comes first in the page, straight after the skip link, so the keyboard and a screen reader meet it at the start.
  • Accept all and Reject all are the same style and size, one press each.
  • It never traps the focus or covers the whole page: the page behind can be read and used without answering.
  • Asked for again from Cookie settings, it takes the focus, so it is read out. After a choice the focus goes back to Cookie settings.
  • Nothing that sets a cookie loads before Accept. The link to the cookie policy is underlined.

What you need to do

  • A cookie policy page that names the cookies and how long they last.
  • A Cookie settings button somewhere on every page: the footer has one.

Keyboard

KeyWhat it does
TabAfter the skip link: the cookie policy link, Reject all, Accept all, then the page.
Enter or SpaceMakes the choice and puts the banner away.

What a screen reader is told

  • A region, "Cookie notice", with a paragraph, a link and two buttons.

This is what the browser reports to assistive technology. What each screen reader then says varies, and has not been listened to yet.

WCAG 2.2

CriterionLevelHow this meets it
1.4.1 Use of ColorAThe policy link is underlined, not only coloured.
2.1.2 No Keyboard TrapATab leaves it; nothing holds the focus.
2.4.3 Focus OrderAFirst in the page’s order; focus is handed back after a choice.
2.5.8 Target Size (Minimum)AAButtons are 38px high.
3.2.6 Consistent HelpACookie settings is in the same place on every page.
4.1.2 Name, Role, ValueAA named region with native buttons.

The criteria this component has a part in. A page that uses it still has to meet the rest.

Checked

CheckHowResult
Automated (axe-core)WCAG 2.0, 2.1 and 2.2 rules at A and AA, the page in light and in darkPassed
Nothing found, light or dark
Narrow screenNo sideways scrolling at 320px wide (WCAG 1.4.10)Passed
No sideways scrolling
Keyboard and what the browser reportsReal key presses on the live example, and the role, name and state given to assistive technologyPassed
11 of 11 checks pass
On paperSomnia’s print check: no overlaps, stranded headings or controls on the pagePassed
No faults on 6 sheets
Screen readerListened to by a person, in VoiceOver and NVDANot yet
Not yet checked by a person

The 11 checks made with the keyboard, on the example at the top of this page:

  • Passed The two choices are the same style and height, side by side
  • Passed They are buttons named "Reject all" and "Accept all", with Reject first
  • Passed Tab goes to the cookie policy link, then Reject all, then Accept all
  • Passed The policy link is underlined, and named by its words
  • Passed Its words have at least 4.5:1 against the banner, in light and dark
  • Passed The buttons are at least 24px high
  • Passed On this site’s home page the banner shows on a first visit, as a region named "Cookie notice", and nothing from Google has loaded
  • Passed It comes straight after the skip link for the keyboard: the policy link, Reject all, Accept all, then the page
  • Passed Reject all puts it away, keeps the choice, loads nothing from Google, and the keyboard carries on from the top of the page
  • Passed Accept all puts it away and only then asks Google for its script
  • Passed Cookie settings in the footer brings it back with the focus on it, and a choice puts the focus back on Cookie settings

Run by script on against Somnia DS 1.89.0, in Chromium with axe-core 4.14.0. How these checks work, and every component's results.

Not yet checked

  • How it sounds in a screen reader (VoiceOver, NVDA, TalkBack) has not been checked by a person. The roles, names and states the browser reports are checked by script; what is actually spoken is not.
  • Windows high contrast (forced colours) has not been looked at by a person.
  • On a small phone the banner covers the foot of the page until it is answered. Whether it can hide something that has the keyboard’s focus (WCAG 2.4.11) has not been checked page by page.

Evidence

Where it's used

WhereFor
mediadreams.co.ukEvery page, on a first visit: it has used Google Analytics beside Umami since 4 November 2026.
Headland YachtingIts live pages, the same way. Not on staging.

What we saw, and what changed

WhenWhat we sawWhat changed
The banner’s words implied the site needed cookies to work.They say what accepting does, and that rejecting changes nothing (1.18.0).
The two choices were not equal, and a choice was kept for good."Accept all" and "Reject all", alike; the choice is asked for again after 12 months (1.36.0).
Writing this page’s checks. The banner came last in the page, after everything else. A choice hid it and left the focus at the top of the page. Asked for again from Cookie settings, it appeared without the focus or a word to a screen reader.It comes first, after the skip link; it takes the focus when asked for and gives it back after a choice (1.87.0).
This page said mediadreams.co.uk shows no banner. It has shown one since Google Analytics was added on 4 November.The page says so, and its checks now run on this site’s own banner.

From building and using it on real sites, each entry taken from the changelog or the build's own notes. This is observation by the studio and its clients, not research sessions with users.

What we don't know yet

  • How many visitors accept, reject or ignore it is not counted, by design: counting them would need the very thing being asked about.