In JavaScript, an element receives beforematch when it is in the hidden until found state and the browser is about to reveal it because the user found the content via find in page or fragment navigation (MDN).
Register a listener with addEventListener. Check readiness and browser support before you rely on this event.
Syntax
Listen for beforematch. Start with this line.
JavaScript
el.addEventListener("beforematch", fn)
Call
What it does
el.addEventListener("beforematch", fn)
Primary signature.
Built into the browser. Listen with el.addEventListener("beforematch", …) — no import required.
Library declarations
JavaScript
el.addEventListener("beforematch", fn)
Parameters
Parameter
Description
hidden="until-found"
Required. Enables searchable hidden state
Handler work
Optional. Run just before reveal
Return Value
Return Value
Description
*
Fires as an Element event (listener receives the Event object).
JavaScript Examples
Example 1 — Listen and Update Text (MDN)
When the fragment link reveals the box, update its text in beforematch.
beforematch supported
/* or: use a manual expand fallback */
How It Works
Test "onbeforematch" in …. Cheap capability check.
If missing, keep a normal expand/collapse control.
Also test in real browsers that until-found reveals as expected.
MDN note: without support, hidden may behave like boolean hide.
Compatibility
Browser Support
Element.beforematch is marked Baseline Newly available on MDN (since December 2025). Logos use the shared browser-image-sprite.png sprite from this project.
✓ Baseline · Newly available
Element beforematch
Fires before a hidden-until-found element is revealed by find-in-page or a fragment link.
NewlyAvailable
Google ChromeSupported in recent versions
Supported
Mozilla FirefoxSupported in recent versions
Supported
Apple SafariSupported in recent versions
Supported
Microsoft EdgeSupported · Chromium
Supported
OperaSupported in recent versions
Supported
Internet ExplorerNot supported
Not supported
beforematchBaseline 2025
Bottom line: Safe in latest browsers. Feature-detect and keep a manual expand fallback for older engines. See the MDN Element beforematch reference.
Frequently Asked Questions
An element receives beforematch when it is in the hidden until found state and the browser is about to reveal its content because the user found it via find-in-page or fragment navigation (MDN).
No. MDN marks Element beforematch as Baseline Newly available (since December 2025). It is not Deprecated, Experimental, or Non-standard. Older browsers may still lack support.
A generic Event. There are no beforematch-only properties beyond the usual Event interface.
Set the HTML hidden attribute to until-found (hidden="until-found"). The element stays visually hidden but remains searchable and reachable by fragment links. When a match scrolls to it, the browser fires beforematch, removes hidden, then scrolls (MDN).
First beforematch fires on the hidden element, then the browser removes the hidden attribute, then it scrolls to the element (MDN).
A practical check is: "onbeforematch" in document.documentElement (or HTMLElement.prototype). Also verify hidden="until-found" behavior in your target browsers.