document.elementFromPoint(x, y) returns the topmost Element at viewport coordinates (x, y). If the point is outside the visible document (or a coordinate is negative), it returns null (MDN).
Pass the required arguments shown below. Check return values and browser support before you rely on the result.
Syntax
Call document.elementFromPoint. Start with this line.
JavaScript
document.elementFromPoint(x, y)
Call
What it does
document.elementFromPoint(x, y)
Primary signature.
document.elementFromPoint(...)
Call with the arguments your case needs.
Built into the browser. Call elementFromPoint(...) on document — no import required.
Library declarations
JavaScript
document.elementFromPoint(x, y)
Parameters
Parameter
Description
x
Required. Horizontal viewport coordinate
y
Required. Vertical viewport coordinate
Return Value
Return Value
Description
*
Topmost Element, or null
JavaScript Examples
Example 1 — Hit a Button
Measure the button, then ask which element sits at that viewport point.
Document.elementFromPoint() is Baseline Widely available (MDN). It is not Deprecated, Experimental, or Non-standard.
✓ Baseline · Widely available
Document.elementFromPoint()
Supported in every modern browser. Safe for hit-testing with viewport coordinates.
99%Modern browser support
Google ChromeAll versions · Desktop & Mobile
Full support
Mozilla FirefoxAll versions · Desktop & Mobile
Full support
Apple SafariAll versions · macOS & iOS
Full support
Microsoft EdgeAll versions · Chromium & Legacy
Full support
Internet ExplorerIE 6+ · Legacy environments
Full support
OperaAll modern versions
Full support
document.elementFromPoint()Excellent
Bottom line: Safe everywhere. Focus on viewport coords, null checks, and whether you need the full stack via elementsFromPoint.
Frequently Asked Questions
MDN: Document.elementFromPoint() returns the topmost Element at the specified coordinates relative to the viewport.
No. MDN marks Document.elementFromPoint() as Baseline Widely available. It is not Deprecated, Experimental, or Non-standard.
MDN: x is the horizontal coordinate from the left edge of the current viewport; y is the vertical coordinate from the top edge of the current viewport.
MDN: if the specified point is outside the visible bounds of the document, or either coordinate is negative, the result is null.
MDN: elements with pointer-events set to none are ignored, and the element below is returned.
MDN: if you need the specific position inside the element (for example a text offset), use Document.caretPositionFromPoint(). elementFromPoint only returns the topmost Element.