Skip to content

New CSS Technique for Focus Not Obscured: z-index focus modifier #3578

@dav-idc

Description

@dav-idc

I'm proposing a potentially unpopular CSS technique to meet the AAA level criterion, '2.4.12 Focus not Obscured (Enhanced)'.

As of the creation of this GitHub issue, there are no techniques exclusive to the AAA level of 'Focus not obscured'. The one technique offered, technique C43, is also applied to the AA level.

The problem

The AAA level criterion for 'Focus not obscured' has a very high standard for success:

"When a user interface component receives keyboard focus, no part of the component is hidden by author-created content."

This creates a difficult scenario, which doesn't yet appear to have a sufficient technique to solve it.
There's a chance to fail 2.4.12 any time that all the following are true:

  • there's at least one 'pop-over' element
  • the pop-over element is situated over top of 'body content' areas (basically, situated where it may overlap any flow content and not situated over a blank area)
  • the pop-over persists without focus

When these 3 things are true, there's a chance that focused 'body content' elements become obscured by the pop-over element.

The solution

Basically: on focus, set the z-index really high for 'body content' elements in the given area.

This is a potentially controversial solution, but I believe it's worth considering due to the current absence of any alternative AAA-level 'focus not obscured' techniques.

Example CSS

.thing:focus {
    position: relative;
    z-index: calc(infinity) !important;
}'

Pros and cons

This works because:

  1. it can be applied to a specific section of content (such as a side-navigation)
  2. it will guarantee that the focused element is right on top, unobscured
  3. it uses simple CSS properties and selectors

This might be controversial because:

  1. playing with z-index when it's not necessary can be risky (at least, I am sensing a vibe that it's taboo to use z-index frivolously)
  2. there's risks of broken interface if it's applied to a whole page / site
  3. it requires careful implementation, since elements need a declared position property

Additional details

This solution requires all focusable elements which might be obscured by the pop-over element to have:

  • a CSS position property (like position: relative or position: absolute
  • a solid background of some type behind the text (like background: white)

It also requires careful selection of a z-index value. I tried various index amounts, to try and find a universally high enough value to override pop-over elements like chatbots, cookie banners, menus, etc. The only one that is guaranteed to work is pretty much just infinity. It seems ridiculous, but calc(infinity) might be appropriate to guarantee focus is never obscured.

Why is this only for the 'enhanced' level?

I believe this technique should be exclusive to the 'enhanced' level, because it specifically solves the problem of making sure no part of a focused element is obscured. This technique isn't really needed to meet the 'minimum' criterion, and would be a bit overkill for that level. There are other techniques, including the existing scroll-margin technique, that already work well for the AA 'minimum' criterion for 'focus not obscured'.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions