MouseEvent.layerY is a non-standard read-only Y coordinate relative to the current “layer.” Learn how positioned elements change its meaning, how it compares to pageY, what to use instead, and five try-it labs.
01
Kind
Instance property
02
Returns
Integer (CSS px)
03
Status
Non-standard
04
Access
event.layerY
05
Pair with
layerX
06
Prefer
offsetY / pageY
Fundamentals
Introduction
Older browsers exposed layerX / layerY for mouse position relative to a “layer.” In practice: for normal flow content it often behaves like document coordinates; inside an element with CSS positioning (absolute, relative, fixed, …) it is relative to that positioned box.
JavaScript
element.addEventListener("mousedown", (event) => {
console.log(event.layerY); // non-standard — may be undefined
});
💡
Beginner tip
Treat layerY as legacy reading material. For new code, pick a standard coordinate: clientY (viewport), pageY (document), or offsetY (target).
Concept
Understanding the Property
MDN: MouseEvent.layerY returns the vertical coordinate of the event relative to the current layer. It takes page scrolling into account and returns a value relative to the whole document unless the event occurs inside a positioned element, where the value is relative to the top-left of that positioned element.
Instance — read event.layerY in a handler.
Integer pixels — Y when the mouse event fired (when supported).
Non-standard — not in any official specification.
Position-sensitive — meaning changes inside positioned elements.
Foundation
📝 Syntax
JavaScript
const y = mouseEvent.layerY;
Value
An integer in pixels for the Y coordinate of the pointer when the event fired (if the engine exposes the property).
Safe read with fallback
JavaScript
function getY(event) {
if (typeof event.layerY === "number") {
return event.layerY; // legacy / non-standard
}
return event.pageY; // standard fallback
}
Without a positioned ancestor changing the layer origin, both properties often report similar document-relative Y values.
📈 Positioned Elements & Safer APIs
See the MDN positioned-div behavior and standard replacements.
Example 3 — Positioned Element Changes Origin
Inside position: absolute, layerY is relative to that box.
JavaScript
positioned.addEventListener("mousedown", (e) => {
console.log({
layerY: e.layerY, // often relative to positioned box
pageY: e.pageY, // still absolute in the document
offsetY: e.offsetY
});
});
MouseEvent.layerY is a Non-standard property. Logos use the shared browser-image-sprite.png sprite. Expect incomplete or engine-specific behavior; do not require it for production UX.
✓ Non-standard · Limited
MouseEvent.layerY
Legacy layer-relative Y. Feature-detect; prefer offsetY, pageY, or clientY.
LimitedNon-standard
Google ChromeMay expose layerY (non-standard)
Limited
Mozilla FirefoxMay expose layerY (non-standard)
Limited
Apple SafariMay expose layerY (non-standard)
Limited
Microsoft EdgeChromium-based; non-standard
Limited
OperaChromium-based; non-standard
Limited
Internet ExplorerLegacy exposure possible
Limited
layerYLimited
Bottom line: Non-standard vertical layer coordinate; use standard mouse Y properties for new code.
Wrap Up
Conclusion
event.layerY is a non-standard vertical coordinate tied to the current layer (often the document, or a positioned element). Learn it for legacy code, then ship with pageY, clientY, or offsetY instead.
Compare positioned vs unpositioned clicks while learning
Document why legacy code still uses layerY
Pair understanding with layerX
❌ Don’t
Ship production UX that requires layerY
Assume it equals pageY inside positioned boxes
Skip fallbacks when the property is missing
Confuse it with standard offsetY
Treat non-standard APIs as future-proof
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about layerY
Non-standard layer Y—learn it, prefer standards.
5
Core concepts
⚠️01
Non-standard
no web spec
Status
🖱️02
Instance
on the event
Kind
📐03
Positioned
origin changes
Layout
⚖️04
≠ always pageY
check context
Compare
🛡️05
Prefer standards
page/client/offset
Safety
❓ Frequently Asked Questions
It is a non-standard, read-only number: the vertical mouse coordinate relative to the current layer. Outside positioned elements it is often similar to pageY; inside a positioned element it is relative to that element’s top-left.
MDN marks it Non-standard — not part of any specification. It is not labeled Deprecated or Experimental on that MDN page, but you should not rely on it in production cross-browser code.
pageY is the document Y including scroll. layerY accounts for scroll too, but when the event is inside a positioned element, layerY is relative to that positioned element instead of the whole document.
Prefer standard properties: offsetY for coordinates relative to the event target, pageY for document coordinates, or clientY for viewport coordinates.
Support is limited and non-standard. Always feature-detect (for example typeof event.layerY === "number") and provide a fallback using pageY or offsetY.
Yes. layerX is the horizontal counterpart with the same non-standard status and positioning rules.
Did you know?
MDN’s classic demo places one unpositioned div and one position: absolute div side by side. Clicking both while watching layerY vs pageY is the fastest way to feel why this property is confusing—and why standards replaced it.