Skip to content
easeweb
Search topics

Cookie banners that hide keyboard focus and come last

A cookie banner fixed over the footer hides links that take focus behind it, or, added after the footer, is the last thing Tab and screen readers reach.

WCAG 2.2
SC 2.4.3ASC 2.4.11AA· new in 2.2
Required by
Section 508 · EN 301 549 (EU)
Broken document.body.append(banner)
The accessibility problem illustrated: Motor:Why is the banner last?
01

The problem

Keyboard users tab onto links hidden behind the cookie banner, the footer's among them, without seeing where focus is, and they and screen reader users reach the banner only after the whole page

02

Try it

Press Tab from the top of the page to the footer, and watch where focus is

  • Broken 1: count the presses to the banner. Near the bottom of the page, does focus slip behind it, where you can no longer see it?

  • Broken 2: the banner comes first. Tab past it to the footer: can you see Contact, Press and Jobs, or scroll them into view?

  • Apply a fix. 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

Make the banner the first thing anyone reaches

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>
What is wrong2 points
  • Tab and a screen reader reach the banner last. document.body.append() adds it after the footer, as the last element in the body.
  • Focus on a link behind the banner can't be seen. position: sticky keeps the banner over the bottom of the window from the moment the page loads until the page is scrolled to its end.
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>
How it is fixed4 steps
  1. Put the banner first in the body, so it is the first Tab stop and the first thing a screen reader reads. If a script builds the banner, add it with document.body.prepend(banner) instead of append().
  2. Make it a section named by its heading, so it has a name in the landmarks list.
  3. Give it position: static. It sits in the page flow at the top instead of floating over it, so it cannot hide focus anywhere.
  4. After a choice, hide the question, show the confirmation in the same place and move focus to it, so nobody is dropped at an unknown point.

This fixes both Befores and passes 2.4.3 and 2.4.11.

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.

How screen readers handle <dialog>

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.

EaseWeb service

Fixed it? Keep it from coming back.

I turn guides like this one into rules your coding agents follow and checks your CI runs. Then I retest by hand with a keyboard and screen readers, periodically.

See the service