Skip to content
easeweb
Search topics

Cookie banners that keyboard users reach last

A consent script adds the banner after the footer and fixes it to the bottom of the window, so it is drawn in front of the page but comes last in the order Tab and screen readers follow.

WCAG 2.2
SC 2.4.3ASC 2.1.2ASC 2.4.11AA· new in 2.2
Required by
Section 508 · EN 301 549 (EU)
Broken document.body.append(banner)
The accessibility problem illustrated: Drawn in front of the page, reached last.
01

The problem

Keyboard and screen reader users meet the cookie banner only after the whole page, and it hides part of the page from them on the way.

02

Try it

Press Tab from the top of the page until you reach the cookie banner.

Count the presses, and watch the links near the bottom of the page: do any slip behind the banner? For the consent dialog, press Open the page first.

Broken Can you fix this?

We use cookies to count visits and improve the site.

Choose cookies

A recreated demo. The broken version is intentionally inaccessible.

03

The fix

Put the banner first in the page, or open it as a modal dialog that Escape closes, so it is the first thing anyone reaches.

  1. 1On a new visit, the banner is the first thing Tab and a screen reader reach.
  2. 2While it shows, it never hides the focused control.
  3. 3Leaving it takes Tab, an answer or Escape, never a reload.
Before A banner added after the footer
<body>  <header class="site-header">…</header>  <main>…</main>  <footer>…</footer>  <div class="cookie-banner">    <p>We use cookies to count visits and improve the site.</p>    <button type="button">Accept all</button>    <button type="button">Reject all</button>    <a href="/cookies">Choose cookies</a>  </div></body>
After

The banner first in the page

<body>  <section class="cookie-banner" aria-labelledby="cookie-title">    <div class="cookie-question">      <h2 id="cookie-title">Cookies on Harbour Museum</h2>      <p>We use cookies to count visits and improve the site.</p>      <button type="button" value="accept">Accept all</button>      <button type="button" value="reject">Reject all</button>      <a href="/cookies">Choose cookies</a>    </div>    <p class="cookie-saved" tabindex="-1" hidden>      Your cookie choice is saved. You can change it on the cookies page.    </p>  </section>  <header class="site-header">…</header>  <main>…</main>  <footer>…</footer></body>

Fixing this with an AI coding assistant? Get this guide as Markdown

04

Verify the fix

5 checks, no mouse.

Test with: Keyboard, Screen reader, Zoom

0 of 5 checked

Record the OS, browser and assistive-technology versions, the build, the date, and the actual result of each step. Repeat after the consent platform or its settings change.

Limits

This is a starting pattern, not a guarantee for every application. It covers how the banner is reached and what it hides, not what counts as valid consent: decide with whoever owns consent what each choice saves, and whether Escape may leave the question unanswered. Auditors differ on whether a banner placed last fails 2.4.3 on its own, but the focus hidden behind it fails 2.4.11 whenever it happens. Where Tab carries on after a banner or dialog is removed differs between browsers, so check it in the ones you support.

This is a recreated teaching example, not a finding about a named client. The code is a starting pattern: test it in your own product. No completed assistive-technology test is claimed here.

Keep this fixed as your code changes.

Turn guides like this into rules your coding agents and CI follow, then have the result retested with a keyboard and screen readers.

How retests work