Pick a standard API.offsetX for element-local hit testing.
Keep a fallback helper. Useful when exploring old code.
Do not depend on layerX alone. Non-standard support varies.
Teach both. Know it when you see it; prefer standards when you write it.
Compatibility
Browser Support
MouseEvent.layerX is marked Non-standard on MDN. Engines may implement it, but it is not a safe production baseline like offsetX / pageX.
✓ Non-standard
MouseEvent.layerX
Horizontal coordinate relative to the current layer. Non-standard — feature-detect and prefer offsetX, pageX, or clientX for new code.
VariesNon-standard
Google ChromeSupported*
Partial
Microsoft EdgeSupported*
Partial
Mozilla FirefoxSupported*
Partial
Apple SafariSupported*
Partial
OperaSupported*
Partial
Internet ExplorerLegacy
Partial
layerXUse with care
Bottom line: Educational / legacy reading only for most apps. See the MDN layerX reference.
Frequently Asked Questions
It is a read-only number: the horizontal mouse coordinate relative to the current layer. Outside positioned elements it is often similar to pageX; inside a positioned element it is relative to that element’s top-left.
MDN marks MouseEvent.layerX as Non-standard on the MouseEvent interface. It is not labeled Deprecated or Experimental, but you should not rely on it in production cross-browser code — prefer offsetX, pageX, or clientX.
pageX is the document X including scroll. layerX also accounts for scroll, but when the event is inside a positioned element, layerX is relative to that positioned element instead of the whole document.
Prefer standard properties: offsetX for coordinates relative to the event target, pageX for document coordinates, or clientX for viewport coordinates.
Support is limited and non-standard. Always feature-detect (for example "layerX" in event) and provide a fallback using pageX or offsetX.
Yes. layerY is the vertical counterpart with the same non-standard status and positioning rules.