WCAG 2.4.12: Focus Not Obscured (Enhanced)
WCAG 2.4.12: Focus Not Obscured (Enhanced)
WCAG 2.4.12, titled "Focus Not Obscured (Enhanced)", is a Level AA success criterion introduced in WCAG 2.1. Its primary objective is to ensure that when a keyboard focusable component receives focus, no part of its visual focus indicator is hidden by author-created content. This criterion builds upon the fundamental requirement of a visible focus indicator (WCAG 2.4.7 Focus Visible) by specifically addressing instances where parts of that indicator might be unintentionally covered.
A focus indicator is the visual cue (e.g., an outline, a color change, an underline) that highlights which interactive element currently has keyboard focus. This criterion mandates that this indicator must be fully visible and unobstructed, allowing users to clearly perceive where their keyboard interaction will take effect.
Why This Criterion Matters
The ability to navigate a web page using only a keyboard is fundamental for many users. The visual focus indicator is their primary means of understanding their current position and predicting their next interaction. When this indicator is obscured, it significantly degrades the user experience and can make a website unusable for certain individuals.
When focus indicators are obscured, users can easily lose their place, skip over critical elements, or inadvertently activate the wrong controls. This can lead to a sense of being lost or unable to complete basic interactions, making the website inaccessible.
Success Criteria and Requirements (WCAG 2.1, Level AA)
The formal wording for WCAG 2.4.12 Focus Not Obscured (Enhanced) is:
2.4.12 Focus Not Obscured (Enhanced): When keyboard focusable components receive focus, no part of the component is hidden by author-created content.
Key terms and implications:
This criterion applies to all situations where focusable elements exist and where author-created content could potentially overlap or obscure them.
Practical Guidelines for Compliance
Achieving compliance with 2.4.12 primarily involves careful design and CSS implementation, especially when using fixed or sticky positioning for elements.
Examples of Correct and Incorrect Implementations
Incorrect Implementation: Fixed Header Obscuring Focus
In this example, a fixed header covers the top portion of a focused input field or link when the page is scrolled.
HTML
Explanation: When the user tabs to the input field and it scrolls up, the fixed header with height: 60px overlaps and hides the top part of the input’s focus outline and potentially some of its content. The `padding-top` on `.content` is not enough to account for the header’s height if the element itself is at the very top of the scroll view.
Correct Implementation: Preventing Focus Obscurity
To fix the issue, we adjust the main content area to always start below the fixed header. Additionally, we use scroll-margin-top for better scroll behavior for focusable elements.
HTML
Explanation: By adding padding-top: var(--header-height); to the body, we ensure that the content visually starts below the fixed header. Additionally, applying scroll-margin-top to focusable elements ensures that when they receive focus and are scrolled into view, they are positioned far enough down from the top edge to clear the fixed header and its focus outline.
JavaScript for Dynamic Focus Management (Advanced)
For complex dynamic content or single-page applications, you might need JavaScript to ensure focus is always visible, especially when new content is loaded or when focus needs to be programmatically managed.
HTML (minimal)
JavaScript
Explanation: When the "Show Form" button is clicked, the form appears, and focus is programmatically moved to the first input field. The scrollIntoView method, combined with the CSS scroll-margin-top, ensures that the focused input is brought into the viewport with enough clearance from any fixed elements (like a header), so its focus indicator is fully visible.
Best Practices and Common Pitfalls
Best Practices
Common Pitfalls
By adhering to these guidelines and conducting thorough accessibility testing, developers can ensure that their web applications meet WCAG 2.4.12 and provide an inclusive experience for all users, especially those who rely on keyboard navigation.
Related posts
- WCAG 5.2.3: Complete processes
- WCAG 5.2.4: Only Accessibility-Supported Ways of Using Technologies
- WCAG 5.2.5: Non-Interference
- WCAG 5.3.1: Required elements of the conformity declaration
- WCAG 5.3.2: Optional Components of a Conformance Claim
Still looking for answers?
Ask our experts using online chat