← Back to release summary

Hidden=until-found HTML attribute and beforematch event

Category
DOM
Type
New or changed feature
Status
In development (Chrome In development)
Intent stage
Prepare to ship

Summary

This feature extends the existing hidden attribute with a new value, "until-found", which makes the element searchable by find-in-page, scroll to text fragment, and fragment navigation. When these search/navigation features want to scroll to something inside a hidden=until-found element, the browser removes the hidden attribute from the element and fires the "beforematch" event on it so that the newly revealed content can be scrolled into view.

Motivation

With the evolution of the web, there are always new and interesting ways that developers choose to organize the information on their pages. Some of these approaches (e.g. the common case of text scrolling), lend themselves naturally to user-agent features like find-in-page. This is not an accident, since find-in-page was designed with common use-cases in mind. However, other approaches like collapsed sections of text do not work well with user-agent features since the page does not get any indication that the user initiated a find-in-page request, fragment navigation, or scroll-to-text navigation. The beforematch event is a step in the direction that allows developers to leverage information that the user-agent already has to make these search and navigation experiences great. Specifically, with hidden but matchable content, it will be possible to process text for find-in-page match in sections that are not visible. In turn, the beforematch event will be fired on hidden (a.k.a. collapsed) sections, allowing the developer to unhide the section. The net effect is that the user is able to use find-in-page or link navigation to find content in collapsed sections -- something that is not currently possible. Even without hidden but matchable features, beforematch is a useful signal to the page which allows custom styling of the matched element, which is now only possible with approximations from scroll positions and intersection observations.

Standards & signals

Docs: https://github.com/WICG/display-locking/blob/master/explainers/hidden-content-explainer.md

Explainers: https://github.com/WICG/display-locking/blob/master/explainers/hidden-content-explainer.md

View on chromestatus.com