Skip to content
easeweb
Search topics

Sticky headers and banners that hide keyboard focus

The browser treats a link under a sticky header or fixed cookie banner as already in view, so it never scrolls it out from under the bar.

WCAG 2.2
SC 2.4.11AA· new in 2.2
Required by
Not required by Section 508 or EN 301 549
Broken
The accessibility problem illustrated: Motor:Where did I go?
01

The problem

Keyboard users tab to a link they cannot see, because a header or banner is drawn over it

02

Try it

Press Tab down the list, then Shift + Tab back up

Watch each article link as it gets focus. Can you always see it, or does it slip under the header or the cookie banner?

Broken Can you fix this?

BrokenBars with nothing reserving their space
Garden Notes

We use cookies Garden Notes uses cookies to remember your settings and to count visits. You can change this at any time.

A recreated demo. The broken version is intentionally inaccessible.

03

The fix

Keep sticky bars from covering keyboard focus

Before
BrokenBars with nothing reserving their space
.site-header {  position: sticky;  top: 0;  height: 4rem;}.cookie-banner {  position: fixed;  inset-inline: 0;  bottom: 0;  height: 5rem;}
What is wrong3 points
  • Part of the page is always hidden. The page scrolls under both bars.
  • The browser doesn't bring hidden links out. Nothing tells it that the top 4rem and bottom 5rem of the window are covered.
  • A focused link can stay hidden. Every link the browser scrolls into view on focus stops under one of the bars.
After

Scroll-padding the height of the bars

:root {  --header-height: 4rem;  --banner-height: 5rem;}.site-header {  position: sticky;  top: 0;  height: var(--header-height);}.cookie-banner {  position: fixed;  inset-inline: 0;  bottom: 0;  height: var(--banner-height);}html {  scroll-padding-top: var(--header-height);  scroll-padding-bottom: var(--banner-height);}/* When the banner is answered and removed, give the space back. */html:not(:has(.cookie-banner)) {  scroll-padding-bottom: 0;}
How it is fixed3 steps
  1. Put the two heights in tokens, and size the bars from them.
  2. Set scroll-padding-top and scroll-padding-bottom on html to the same tokens. They tell the browser which part of the window is really visible, so focus scrolling, anchor links and scrollIntoView stop clear of the bars.
  3. When the banner is answered and removed, set the bottom padding back to 0.

This fixes the Before and passes 2.4.11. The heights and the padding come from the same tokens, so they cannot drift apart, but this works only while the bars keep those heights: if the header's text wraps at a narrow width or when enlarged and the header grows, the padding must grow with it. Use rem heights that scale with the text, or update the variables from a ResizeObserver. Set scroll-padding on the element that actually scrolls; if the content scrolls inside a container, put it there instead of on html.

04

Verify the fix

4 checks, no mouse.

Test with: Keyboard, Zoom

0 of 4 checked

Record the OS, browser and assistive-technology versions, the build, the date, and the actual result of each step. Repeat after the header, banners or page layout change.

Limits

This is a starting pattern, not a guarantee for every application. Browsers apply scroll-padding to focus scrolling in their current versions, but check yours, and check scroll containers inside the page, such as carousels and side panels, which each need their own padding. Token names in the snippets are placeholders for your own design tokens.

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