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.
document.body.append(banner) 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
The home page of Harbour Museum has a header with four links (Visit, Exhibitions, Events, Shop), six links in the page (Opening hours, Book a guided tour, Family trail, Ship models gallery, Café menu, Access guide) and three in the footer (Contact, Press, Jobs). On a first visit, a cookie banner covers the bottom of the window: "We use cookies to count visits and improve the site", with Accept all, Reject all and Choose cookies. It is the first thing a sighted mouse user sees. Press Tab from the top of the page. After the menu, focus moves down the page's links, and the ones near the bottom of the window, such as Family trail, are under the banner. The page does not move: focus is on a link nobody can see, so the user can't tell what Enter would open. The same happens to each link that reaches the bottom of the window as the page scrolls. Accept all comes only on the fourteenth press. A screen reader reading from the top reads the footer before it reads the banner.
Some consent scripts already add the banner at the start of the page, and still fix it to the bottom of the window. Tab then reaches Accept all first, but the banner now takes no space in the page, so the footer never comes out: at the end of the page there is nothing left to scroll, so Contact, Press and Jobs stay under the banner however far anyone scrolls. Focus on them is never visible, and even a mouse user can't read them until they answer.
The consent script builds the banner when the page loads and adds it with document.body.append(), after the footer. CSS then sticks it to the bottom of the window. Where it is drawn and where it sits in the source have nothing to do with each other.
That is why focus disappears. When focus moves, the browser scrolls only if the element is outside the window, and a link behind the banner is inside it, so the page stays still. When the browser does scroll to a link further down, it can stop with the link at the bottom edge, under the banner again. Nothing tells the browser that part of the window is covered. Success criterion 2.4.11 requires that a focused control is not entirely hidden by content the author put on the page, and its Understanding document names this case: a cookie banner implemented as sticky content fails it.
The second Before moves the banner first, which fixes the order but not what it covers. It is fixed instead of sticky, and a fixed element takes up no space in the page, so the page ends under it and the footer can't scroll out from under the banner at all. On the footer's links, nothing uncovers focus without moving it: scrolling can't, and the banner does not close with Escape.
Tab and screen readers follow the source, so the banner added after the footer also comes last. Success criterion 2.4.3 asks that focus moves in an order that keeps the page usable. The banner is drawn in front of everything and covers part of every screen until it is answered, yet it comes after everything, so a keyboard user has to work through the whole page, with part of it hidden, before they can clear it.
On a phone the banner can fill half the screen, so more of the page sits under it and more Tab presses pass behind it. A floating Add to bag bar adds its own height on top, as in floating buy bars that cover the page when zoomed in.
4 of 10 groups affected
- No vision (affected)
- Low vision (affected)
- Colour vision (not affected)
- No hearing (not affected)
- Hard of hearing (not affected)
- No speech (not affected)
- Motor (affected)
- Reach, strength (not affected)
- Cognitive (affected)
- Seizures (not affected)
- Limited manipulation Sighted keyboard users tab onto links behind the banner without seeing them, so they lose their place and may press Enter on a link they never saw. They also pass every link on the page before they can answer.
- Without vision Screen reader users reading from the top hear the banner only after the footer, if they get that far, so they may not know a choice is waiting or that part of the screen is covered.
- Limited vision People who zoom in see the banner take up much more of the window, so more of the page sits under it while they tab towards it.
- Limited language, cognitive and learning abilities People with attention or short-term memory limitations rely on seeing where focus is to keep their place, and lose it each time a link passes behind the banner.
Each button has a name and the banner has text, so a scan of the page passes it. The order is only wrong compared with where the banner is drawn, and source-order checks do not compare the two. The banner also only appears on a first visit, without a saved choice: a scanner that keeps cookies, or runs after someone accepted, never sees it. Most banners come from a third-party consent platform whose code nobody on the team reads. Generated banner code tends to follow the common tutorial pattern: build the element, append it to the body, fix it to the bottom.
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?
Welcome to the harbour
The fix
Make the banner the first thing anyone reaches
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: stickykeeps the banner over the bottom of the window from the moment the page loads until the page is scrolled to its end.
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
- 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 ofappend(). - Make it a
sectionnamed by its heading, so it has a name in the landmarks list. - Give it
position: static. It sits in the page flow at the top instead of floating over it, so it cannot hide focus anywhere. - 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.
Why this fix: Write the source in the order it is read
The banner first in the page and the consent dialog both pass. The banner first is the smaller change: people can read and use the page and answer when they are ready, and nothing needs managing once it is in the right place. Its cost is that it pushes the page down on a first visit. The dialog makes everyone answer before using the page, and the browser handles focus, the inert background and Escape. Its cost is that it blocks the page for everyone, screen reader users included, before they have heard what the page is. Choose the banner first unless the page really has to wait for an answer. Reserving the banner's height on its own is a stopgap for a banner you cannot move: it keeps focus visible, but a banner added last stays last. For a banner that already comes first but stays fixed, as in the second Before, it is the whole fix.
Most cookie banners are added by a consent management platform, so the markup is not yours to edit. Work through these in order, and stop at the first one that works.
- Check the platform's settings. Many let you choose the layout (a bar at the top, a bar at the bottom, a modal) and where in the page the banner goes. Choose a bar inserted at the start of the body, or a modal that closes on Escape.
- If there is no such setting, move the banner yourself once it appears: watch the body with a
MutationObserver, and when the banner's element is added, move it withdocument.body.prepend(). Disconnect the observer after the move, and check that the banner's buttons still work, because some scripts rebuild the banner and put it back where it was. If it stays fixed to the bottom, reserve its height too, as in the last fix, or it still covers the footer. - If the banner cannot be moved, reserve its height with
scroll-padding-bottomandpadding-bottom, as in the last fix, so focus at least stays in view. Treat that as a stopgap, not the end of the work. - Report the problem to the vendor, with the steps to reproduce it, and ask for their accessibility conformance report. Until it is fixed, list it as a known issue in your accessibility statement.
Check the banner for focus traps while you are there. They are common in vendor code, and they fail 2.1.2 (No Keyboard Trap).
- A banner that does not block the page, but whose script loops Tab inside it until a choice is made.
- A consent dialog that cancels Escape and offers only Accept as a way out.
- A "Choose cookies" panel that opens over the banner and, when closed, drops focus at the top of the document instead of returning it.
Pop-ups that can't be closed with a keyboard, keyboard traps in editors and form fields and modals that leave keyboard focus behind them cover these in detail. Vendor scripts change without a deploy on your side, so repeat the steps under "Verify the fix" after each vendor update and each change to the platform's settings.
It can look like a shortcut: call focus() on the banner's first button when the page loads, and every keyboard user starts there. For a banner that does not block the page, don't. It is not a failure of a success criterion on its own, but placing the banner first in the source already makes it the first Tab stop and the first thing read, and forcing focus there takes away more than it gives.
- Screen reader users lose their bearings. When a page loads, a screen reader announces its title and starts at the top. Moving focus jumps straight to a button, often cutting the title off, so people hear "Accept all, button" without knowing which page they are on.
- People who use screen magnification have their view pulled to wherever the banner is drawn, often the bottom of the window, away from the top of the page they expected to see.
- Keyboard users who want to read first have to deal with the banner before anything else, instead of choosing when to answer it.
The exception is the consent dialog. When the page cannot be used until the question is answered, focus has to move into the dialog, and showModal() does that. Some consent platforms move focus to their banner by default: look for a setting that turns it off, and if there is none, include it in your report to the vendor.
Put the banner before the skip link, as the GOV.UK Design System does. The first Tab then reaches the banner and the second the skip link, and once the banner is answered the skip link is first again. The same guidance advises against fixing the banner to the screen at all, because a fixed banner can cover focused content. If your design keeps it fixed to the bottom, keep it first in the source and reserve its height, as in the focus-not-obscured guide.
Render the banner in the server's HTML when you can. It is then in place before any script runs, and it does not push the page down after people have started reading.
Verify the fix
5 checks, no mouse.
Test with: Keyboard, Screen reader, Zoom
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.