Focus Not Obscured
| Property | Value |
|---|---|
| ID | focus-not-obscured |
| Severity | Error |
| WCAG | 2.4.11 Focus Not Obscured |
| Config | focusNotObscured |
What it checks
Detects when a focused element is not visible because other content covers it. The verdict follows WCAG 2.4.11 (AA): an element is obscured only when it is entirely hidden, so a cover that leaves part of it visible passes.
How it works
For each focused element during the tab crawl, the crawler:
- Samples five points (centre and four inner corners) with
document.elementsFromPoint(), withpointer-eventsforced on so non-interactive overlays are seen too. - Applies a style check: anything stacked above the element that paints (background, image, border, shadow, text, or a painting
::before/::afteron an ancestor) counts as a cover. Transparent,opacitybelow 0.1 andvisibility:hiddencovers do not. - Elements with anything stacked above them are then re-focused and pixel-probed: the element's padded region is screenshotted as-is and again with the element set to
visibility:hidden. Identical renderings mean the element contributes no visible pixels, so it is covered, whatever the mechanism.
The pixel probe overrides the style check when it can decide. When it cannot (the element paints nothing of its own, a capture fails, or focus will not stay on the element) the style result stands. Elements with nothing stacked above them are not probed.
Examples
Fail
<!-- Sticky header covers focused elements when scrolled -->
<header
style="position: fixed; top: 0; width: 100%; height: 60px; z-index: 100;"
>
Navigation
</header>
<main>
<!-- This link might be hidden behind the header when focused -->
<a href="/about">About</a>
</main>Pass
<!-- Header scrolls with content, doesn't obscure -->
<header>Navigation</header>
<main>
<a href="/about">About</a>
</main>How to fix
- Use
scroll-padding-topto account for fixed headers when elements are scrolled into view - Ensure cookie banners and overlays don't cover focusable content
- Use
scroll-marginon focusable elements to provide clearance from sticky elements - Consider dismissing non-essential overlays when the user starts keyboard navigation
Cookie/consent banners
Keylens auto-dismisses known cookie/consent banners before the crawl (see Configuration: prepare phase), so this rule normally evaluates the page in its post-consent state rather than flagging the banner itself. To audit a banner deliberately — e.g. to verify it doesn't obscure focus while open — run with --keep-overlays (prepare.dismissOverlays: false).