Collapsed sections, like an FAQ, have a known problem: if the text is hidden with display: none, the browser’s find-in-page cannot see it. hidden="until-found" hides the content but keeps it searchable. I find it a neat answer to a problem I’d otherwise solve with a script.
Use it as a value of the hidden attribute:
<a href="#answer">Go to the answer</a>
<div id="answer" hidden="until-found">Hidden until found</div>
When Find in page matches text inside it, or someone opens a link with #answer, the browser fires a beforematch event on the element, removes the hidden attribute and scrolls to it. That event is where you update state, for example to open an accordion:
const box = document.querySelector("#answer");
box.addEventListener("beforematch", () => {
box.closest("section").classList.add("open");
});
A plain hidden removes the content from search and from fragment navigation altogether, which is the difference.
Caveats:
- Browsers hide it with
content-visibility: hidden, so the element still has a box in the layout, with its own margin, border and padding. Adjust your CSS if that leaves gaps. - It only reveals when the element is not
display: none,contentsorinline. If your CSS sets one of those on it, the search will not find it. - Support is recent. Web.dev lists Chrome and Edge 102, Firefox 139 and Safari 26.2, and one compatibility site shows Firefox later, so test in the browsers you care about and keep a plain fallback.
Browsers that do not know the value may treat it as a normal hidden attribute, so the content simply stays closed.
Further reading: MDN: hidden attribute, web.dev: New to the web platform in December 2025