brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: hidden="until-found" hides content that Ctrl+F can still find

Web-Development
~/tips/tip-html-hidden-until-found

cat ~/tips/tip-html-hidden-until-found.md

Hides content but lets browser search and #links still find and reveal it.

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, contents or inline. 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

More Web-Development tips ab -n 200 -c 10 https://example.com/ console.assert(items.length > 0, 'cart is empty', items) document.designMode = "on" function save(item) { Save draft All Web-Development tips (67) All topics

Link