Recently, I found myself needing to implement collapsible sections. For this particular use case, using <details> and <summary> elements was too much of a hassle because the CMS did not recognize them as elements and I don’t particularly like nesting headings within a <summary> element, since it makes discovering the expand and collapse trigger more difficult for those navigating by headings. So, I’m turning to the tried and true “Collapsible Sections” pattern.
I’ve used this pattern for accordion components in design systems, built custom elements with it, and used it for cases like this. Here’s what the markup generally looks like:
<section>
<h2>
<button id="section-0-trigger" aria-expanded="false" aria-controls="section-0-content">
Hello, World!
</button>
</h2>
<div id="section-0-content" hidden>Hideable content…</div>
</section>
The JavaScript for it is pretty simple as well:
// Simplified
button.addEventListener("click", () => {
content.hidden = !content.hidden;
button.ariaExpanded = content.hidden ? "false" : "true";
});
While implementing the pattern, I realized that rather than just using hidden as a boolean attribute on its own, I can use the newer until-found attribute-value, so that I could allow the contents of the disclosures to be searchable.
As of writing this, hidden=until-found is only available in Chrome and Firefox. Safari will likely include it in an upcoming release as it is currently available in their latest Technology Preview.
I’ve written on how to polyfill hidden=until-found earlier this year, but unfortunately that doesn’t work in Safari since there’s no good way to observe its “find-in-page” feature. I can still use hidden=until-found though, because it was designed with progressive enhancement in mind.
Unsupporting browsers will hide content visibly and accessibly for any value provided to the hidden attribute (bear in mind that the element property works differently when given boolean values). For those cases, hidden=until-found will work like hidden on its own, since the attribute is present.
Here’s our updated markup:
<section>
<h2>
<button id="section-0-trigger" aria-expanded="false" aria-controls="section-0-content">
Hello, World!
</button>
</h2>
<div id="section-0-content" hidden="until-found">Hideable, but searchable content…</div>
</section>
We’ll need to slightly adjust the JS to use until-found as the value for the attribute when collapsing. Since "until-found" is a truthy value in JavaScript, we’re relying on that both in the condition and when setting the property which sets a boolean in unsupported browsers.
button.addEventListener("click", () => {
content.hidden = content.hidden ? false : "until-found";
button.ariaExpanded = content.hidden ? "false" : "true";
});
Since the content can be expanded when it contains a match for a find-in-page query, I’ll need to listen for the beforematch event for the content, so that I can update the <button> element’s aria-expanded attribute value to reflect when the content is no longer hidden.
content.addEventListener("beforematch", () => {
button.ariaExpanded = "true";
});
So, there you go: with not a whole lot of changes your collapsible sections are now searchable as a progressive enhancement.
Again, if <details> and <summary> elements are suitable use those instead — this is the first rule of ARIA usage. They have the same searchable benefit as hidden=until-found and you don’t need any extra HTML or JavaScript to get them working.
Demo
You can check out a live demo of a searchable, collapsible section below, but it likely will work better on a standalone page to avoid searching this parent document.
Update: June 26, 2026
I’ve become aware of a Safari/VoiceOver bug (Bug 310623) where if you programmatically remove hidden=until-found from an element the accessibility tree doesn’t seem to update to include the content. When content is matched with find-in-page, this doesn’t seem to be an issue. I don’t believe this would have been an issue when I wrote this article as I usually test pretty thoroughly with screen readers. Anyway, either avoid this pattern until that’s fixed or hopefully pressure WebKit to fix it, as the bug was opened three months ago and still doesn’t have a fix.





