Sub topic 14
Accessibility and find-in-page
This chapter assumes you know content-visibility: auto and hidden, and that you can use the browser's find command and a screen reader at a basic level.
Skipped does not mean absent
Skipping rendering saves layout and paint work. It does not remove content from the page's data structures. The DOM, the text, and the links all remain. What differs between auto and hidden is how much of that content the browser exposes to users and assistive technology.
| Behavior | `content-visibility: auto` (skipped) | `content-visibility: hidden` |
|---|---|---|
| In the accessibility tree | Yes | No |
| Found by find-in-page | Yes | No |
| Reachable by fragment links (`#id`) | Yes | No |
| Focusable and selectable | Yes, and focus makes the content relevant | No |
Why `auto` is the safe default
With auto, the browser stops skipping an element when it becomes relevant to the user. An element is relevant when it is near the viewport, when focus is inside it, or when a selection is inside it. Find-in-page and fragment navigation also bring skipped content into the rendered state. So a user who searches for a word in a long article reaches it even if it sits in a skipped section.
Screen readers see the same content as before. Headings and landmarks inside skipped sections still appear in the accessibility tree, so heading navigation keeps working. This is why auto suits long documents and feeds.
Why `hidden` needs care
content-visibility: hidden behaves like display: none for users. The contents are not exposed to assistive technology, and find-in-page cannot see them. Use it only for content the user is not meant to reach until something reveals it, such as an inactive tab. Do not use it to shorten a long page of readable text.
If hidden content should still be searchable, such as a collapsed section, use the hidden="until-found" attribute. Browsers that support it apply the hiding behavior, then reveal the element when find-in-page or a fragment link matches its text.
<details-like>
<div id="faq-shipping" hidden="until-found">
Orders ship within two business days.
</div>
</details-like>
<script>
const answer = document.getElementById('faq-shipping');
answer.addEventListener('beforematch', () => {
console.log('Revealed by find-in-page');
});
</script>The beforematch event fires before the browser reveals the element, so you can update related UI such as an expand icon.
Checking your page
- Search for a word that sits in a skipped section. The browser should scroll to it and render the section.
- Tab through the page. Focus should never land on something invisible.
- Open a headings list in a screen reader. Headings from skipped sections should be listed.
- For
hiddenpanels, confirm that a visible control always reveals them.
Exercise
A long article uses content-visibility: auto on each section. A user searches for a phrase in section 12, which is far below the viewport. What happens, and why would content-visibility: hidden give a different result?
Show answer
With auto, the browser finds the phrase because skipped content stays in the DOM and is searchable. It renders the section and scrolls to the match. With hidden, find-in-page cannot see the contents and the phrase is not found, because the contents are also left out of the accessibility tree. Only a script or the hidden="until-found" attribute can reveal them.