The Problem
Accordions are a popular web design pattern, allowing users to expand and collapse content on demand. When collapsed, browsers usually employ “display: none” to hide the content, which removes it from the page layout flow and renders it unsearchable.
Solution
Add hidden=until-found to the container so the browser can search text and reveal the section if the text is found.
Considerations
- Layout APIs like getBoundingClientRect may report the hidden content in the size even when hidden.
- Users should still be able to see the content without the use of find-in-page
- Child elements won’t be rendered but the container will still be a box so border and size can effect it.
- The beforematch event that is fired when the hidden until found content is about to be shown is still in experimental mode and not currently (Nov/24) supported by
SafariandFirefox.