惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

WordPress大学
WordPress大学
Security Latest
Security Latest
C
Cisco Blogs
P
Palo Alto Networks Blog
Know Your Adversary
Know Your Adversary
Project Zero
Project Zero
C
Cyber Attacks, Cyber Crime and Cyber Security
NISL@THU
NISL@THU
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
S
Secure Thoughts
P
Privacy International News Feed
V
Vulnerabilities – Threatpost
D
Docker
Google Online Security Blog
Google Online Security Blog
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Recent Announcements
Recent Announcements
T
The Exploit Database - CXSecurity.com
G
Google Developers Blog
Schneier on Security
Schneier on Security
小众软件
小众软件
爱范儿
爱范儿
GbyAI
GbyAI
J
Java Code Geeks
T
Tailwind CSS Blog
Cisco Talos Blog
Cisco Talos Blog
The Hacker News
The Hacker News
D
DataBreaches.Net
Blog — PlanetScale
Blog — PlanetScale
TaoSecurity Blog
TaoSecurity Blog
MyScale Blog
MyScale Blog
B
Blog RSS Feed
Cyberwarzone
Cyberwarzone
有赞技术团队
有赞技术团队
Martin Fowler
Martin Fowler
C
CXSECURITY Database RSS Feed - CXSecurity.com
S
Securelist
L
Lohrmann on Cybersecurity
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Y
Y Combinator Blog
S
Schneier on Security
Latest news
Latest news
Apple Machine Learning Research
Apple Machine Learning Research
博客园 - 叶小钗
F
Fortinet All Blogs
M
MIT News - Artificial intelligence
PCI Perspectives
PCI Perspectives
V
V2EX
V2EX - 技术
V2EX - 技术
O
OpenAI News
W
WeLiveSecurity

TetraLogical Blog

Designing for people with reading disabilities - TetraLogical Designing for people who are D/deaf - TetraLogical Designing accessible documents - TetraLogical Introduction to creating accessible documents - TetraLogical Inclusive user research: vulnerable people - TetraLogical Designing for people who are blind - TetraLogical Designing for people with low vision - TetraLogical Meet the team: Niamh Madden - TetraLogical Designing for people with anxiety - TetraLogical Designing for people with disabilities - TetraLogical Accessible building blocks for the web videos - TetraLogical Common accessibility misconceptions - TetraLogical Common misconceptions about testing accessibility - TetraLogical Common misconceptions about implementing accessibility - TetraLogical Common misconceptions about WCAG - TetraLogical Common misconceptions about disability - TetraLogical Meet the team: Grace Snow - TetraLogical Sustainable accessibility in complex organisations: strategic foundations - TetraLogical Sustainable accessibility in complex organisations: organisational realities - TetraLogical Sustainable accessibility in complex organisations: external factors - TetraLogical Common misconceptions about screen readers - TetraLogical Guide to the Inclusive Design Principles - TetraLogical Meet the team: Ian Lloyd - TetraLogical Annotating designs using common language - TetraLogical Meet the team: Catriona Morrison - TetraLogical Championing inclusive language - TetraLogical Press release: TetraLogical launches accessible self-led training courses to help digital teams build confidence in accessibility - TetraLogical Why inclusive products are green products - TetraLogical Accessible Recruitment - TetraLogical Accessibility and the agentic web - TetraLogical Meet the team: Craig Abbott - TetraLogical Foundations: types of assistive technology and adaptive strategies - TetraLogical European Accessibility Act (EAA) FAQ - TetraLogical Screen reader HTML support tables - TetraLogical Interview with Lola Odelola - TetraLogical Understanding EN 17161 Design for All - TetraLogical Inclusive user research: building rapport - TetraLogical Foundations: Keyboard accessibility - TetraLogical Can generative AI write contextual text descriptions? - TetraLogical Understanding the European Accessibility Act (EAA) - TetraLogical Meet Josh: a sportsman who has spinal muscular atrophy - TetraLogical Meet Jonathan: a photographer who has ADHD - TetraLogical Foundations: grouping forms with `<fieldset>` and `<legend>` - TetraLogical XR Accessibility: for people with moving disabilities - TetraLogical Meet Andre: a music producer and blind screen reader user - TetraLogical Foundations: types of disability - TetraLogical Meet Lauren: a film editor who has ADHD - TetraLogical Meet Steve: a photographer who is deaf and low vision - TetraLogical Foundations: form validation and error messages - TetraLogical Meet Hasmukh: a blind cricketer and screen reader user - TetraLogical XR Accessibility: for people with hearing disabilities - TetraLogical XR Accessibility: for people with thinking disabilities - TetraLogical XR Accessibility: for people with seeing disabilities - TetraLogical Introduction to XR Accessibility - TetraLogical Foundations: labelling text fields with input and label - TetraLogical Design patterns and WCAG - TetraLogical Does WCAG 2.2 apply to native apps - TetraLogical Why are my live regions not working? - TetraLogical Building a culture of accessibility - TetraLogical When to use tabindex= Accessibility foundations - TetraLogical Meet the team: Demelza Feltham - TetraLogical Can generative AI help write accessible code? - TetraLogical Meet the team: Steve Faulkner - TetraLogical Meet the team: Gez Lemon - TetraLogical Keyboard accessibility myths and WCAG - TetraLogical Amendment to the Public Sector Accessibility Regulations - TetraLogical What Considerations for TV user interface accessibility - TetraLogical Meet the team: Alistair Duggin - TetraLogical The only accessibility specialist in the room - TetraLogical Meet the team: Ian Pouncey - TetraLogical Meet the team: Dean Holden - TetraLogical Meeting WCAG Level AAA - TetraLogical Foundations: accessible names and descriptions - TetraLogical Inclusive XR: accessible augmented reality experiences - TetraLogical Foundations: pointer gestures - TetraLogical Meet the team: Graeme Coleman - TetraLogical Adding sign language to videos - TetraLogical Foundations: introduction to WAI-ARIA - TetraLogical Meet the team: Joe Lamyman - TetraLogical Inclusive XR: accessible 3D experiences - TetraLogical Foundations: visible focus styles - TetraLogical Foundations: target sizes - TetraLogical Meet the team: Henny Swan - TetraLogical Meet the team: Ela Gorla - TetraLogical Foundations: native versus custom components - TetraLogical Foundations: HTML semantics - TetraLogical Accessibility and supporting Internet Explorer - TetraLogical Meet the team: Felicity Miners-Jones - TetraLogical Accessibility and QR codes - TetraLogical Inclusive user research: recruiting participants - TetraLogical Research insight: accessibility of images - TetraLogical Meet the team: Léonie Watson - TetraLogical Android accessibility: roles and TalkBack - TetraLogical Accessible design systems - TetraLogical Meet the team: Patrick H. Lauke - TetraLogical Inclusive user research: analysing findings - TetraLogical How to write user stories for accessibility - TetraLogical Triaging WCAG 2.1 Level AAA - TetraLogical
Sticky content: focus in view - TetraLogical
2023-06-08 · via TetraLogical Blog

Posted on by Joe Lamyman in Design and development

Tags: Code, WCAG

Sticky content helps prioritise important content so it's always visible, but it can create issues for sighted people who use a keyboard, or a keyboard-like device, as focused controls become hidden behind the sticky content.

This post discusses how you can keep controls behind sticky content visible and usable when they receive focus.

A small amount of CSS is all it takes to make it possible for people to see the content they are interacting with and help you meet the existing 2.4.7 Focus Visible (AA), and the proposed 2.4.11 Focus Not Obscured (Minimum) WCAG success criteria.

If you're not familiar with focus styles, we cover what this means and how you can create visible focus styles in our blog post: Foundations: visible focus styles.

The problem with sticky content

Sticky content remains visible over other content on the page, ensuring the sticky content is always available. It's an effective way of allowing you to visually find important information you may need, at any time. For example, many websites use sticky headers to keep controls visible on long pages to save you from scrolling to the top of the page.

Screenshot demonstrates how Google uses a sticky header to keep the search bar visible on screen, but this obscures the search results content beneath it
Google's sticky header obscuring the TetraLogical link

However, sticky content can obscure content beneath it, and if you use a keyboard to navigate, there may be controls that receive focus, but you can't see.

In this case, the browser is doing everything as expected: the sticky content remains visible and the control receives focus. However, the issue is that the focus is not visible to us.

Example of a sticky header and banner which obscure links - as focus cycles through page links, elements behind/underneath the sticky elements receive focus.

This current behaviour fails 2.4.7 Focus Visible (AA) and 2.4.11 Focus Not Obscured (Minimum) because the focus indicator is not visible, nor is the control that receives focus.

We can use the relatively recent scroll-padding and scroll-margin CSS properties to resolve this issue. These control the padding and margin that are applied to scrollable areas, particularly when content scrolls as a result of keyboard focus being moved. Note that scroll-margin currently has some bugs / browser incompatibilities (particularly in Safari), so we recommend using scroll-padding at the time of writing.

Use the scroll-padding property, setting its value to the height of the "sticky" element. If you're unsure about the element's height, you can use your browser's Developer Tools.

Screenshot that shows the dimensions of the header when hovered over with DevTools open, as well as in the computed section of the elements panel.

The approach works best if you use rem or em units which will scale alongside any zoom or text sizing applied. In the following example, the container has a height of roughly 6rem. Based on this, the CSS you'll need to add is:

scroll-padding-top: 6rem;

To ensure this is applied, you must add the styling to a scroll container. Chromium-based browsers allow this to be applied to the elements themselves, but Safari requires it to be applied to the scroll containers. In the following example, we've chosen to apply it to anything in the HTML or body elements (<html>, <body>).

html, body {
  scroll-padding-top: 6rem;
}

By adding this CSS, when elements receive focus, the page will scroll them into view as normal but will also take into account the scroll padding, making sure that they don't land behind the sticky content.

Example of a sticky header and banner which do not obscure focused links in the page - with the scroll-padding applied, interactive elements receive focus and "move out" from under the sticky content to become visible.

Similar use cases

You can add scroll padding for similar use cases, such as a cookie banner that may be visible.

In the demonstration below, a cookie banner remains visible at the bottom of the screen until it is dismissed. As with the sticky header, we don't want the content to receive focus behind this control. You can resolve this by adding scroll padding. However, as this content can be dismissed, we may not always want a large amount of scroll padding to be applied if it's not visible. In this case, we can use the has() selector to only apply the scroll-padding-bottom when the banner is visible.

:is(html, body):has(aside) {
  scroll-padding-bottom: 6rem;
}
Example of a cookie banner - interactive elements that receive focus are visually scrolled above the cookie banner. When the banner is dismissed, the padding is removed from the bottom of the page.

Shortcomings

One of the limitations of the scroll-margin / scroll-padding approach is that you will need to know the exact height of the sticky content. This may not always be known ahead of time, particularly if the dimensions of the sticky content container can change based on the actual height of its content. In those cases, you may have to resort to additional JavaScript to dynamically change the value of the scroll-margin or scroll-padding.

Summary

  • scroll-margin and scroll-padding can be used to allow controls behind sticky content to become visible when they receive focus
  • Paired with the right CSS selectors, the behaviour can be made specific to the sticky content visible on the screen
  • 2.4.7 Focus Visible (Level AA)

More information

Next steps

Read more about accessible design systems or how our design system assessments gives you the information you need to build accessibility into your products early from the start.