JavaScript MouseEvent layerY Property

Beginner
⏱️ 10 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
Non-standard
Instance property

What You’ll Learn

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

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).

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.

📝 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
}

⚖️ layerY vs Standard Coordinates

PropertyStatusTypical meaning
layerYNon-standardLayer / positioned ancestor Y
pageYStandardDocument Y (includes scroll)
clientYStandardViewport Y
offsetYStandardRelative to the event target

⚡ Quick Reference

GoalCode
Read (if present)event.layerY
Feature-detecttypeof event.layerY === "number"
Document Y (prefer)event.pageY
Target-local Y (prefer)event.offsetY
MDN statusNon-standard (not in any spec)

🔍 At a Glance

Four facts about layerY.

Kind
instance

On the event

Type
number

When present

Status
non-standard

Avoid in production

Pair
layerX

Horizontal twin

Examples Gallery

Examples follow MDN MouseEvent.layerY. Click unpositioned and positioned boxes to see how values diverge from pageY.

📚 Getting Started

Detect support and compare with pageY.

Example 1 — Feature Detection

Never assume layerY exists.

JavaScript
document.addEventListener("mousedown", (e) => {
  const supported = typeof e.layerY === "number";
  console.log(supported ? e.layerY : "layerY not available");
});
Try It Yourself

How It Works

Checking typeof === "number" avoids treating undefined as a coordinate.

Example 2 — Unpositioned Box ≈ pageY

MDN: in normal flow, layerY is often close to pageY.

JavaScript
unpositioned.addEventListener("mousedown", (e) => {
  console.log({
    layerY: e.layerY,
    pageY: e.pageY
  });
});
Try It Yourself

How It Works

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
  });
});
Try It Yourself

How It Works

pageY stays document-absolute. layerY (and often offsetY) can be small when you click near the positioned element’s top-left.

Example 4 — MDN-Style Coordinate Logger

Log parent id, pageX/pageY, and layerX/layerY.

JavaScript
function showCoords(evt) {
  const form = document.forms.form_coords;
  form.parentId.value = evt.target.parentNode.id || "(none)";
  form.pageXCoords.value = evt.pageX;
  form.pageYCoords.value = evt.pageY;
  form.layerXCoords.value = evt.layerX;
  form.layerYCoords.value = evt.layerY;
}

window.addEventListener("mousedown", showCoords);
Try It Yourself

How It Works

This mirrors MDN’s demo: compare absolute document coords with layer coords as you click different boxes.

Example 5 — Prefer Standard Coordinates

Production-friendly helper that ignores layerY.

JavaScript
function pointerY(event, mode = "page") {
  if (mode === "client") return event.clientY;
  if (mode === "offset") return event.offsetY;
  return event.pageY; // default: document
}

document.addEventListener("mousedown", (e) => {
  console.log({
    page: pointerY(e, "page"),
    client: pointerY(e, "client"),
    offset: pointerY(e, "offset")
  });
});
Try It Yourself

How It Works

Choosing an explicit mode keeps your app portable. You can still log layerY while debugging old code paths.

🚀 Common Use Cases

  • Reading legacy code that still inspects layerX / layerY.
  • Comparing positioned vs document coordinates while learning mouse APIs.
  • Migrating old handlers to offsetY, pageY, or clientY.
  • Feature-detecting before touching non-standard properties.
  • Teaching why non-standard APIs are risky in production.

🔧 How It Works

1

Pointer event fires

Browser knows the hit target and layout.

Input
2

Engine picks a layer origin

Document vs nearest positioned ancestor.

Layout
3

Non-standard layerY filled

Only if the engine still implements it.

Event
4

Prefer a standard fallback

Use pageY, clientY, or offsetY in real apps.

📝 Notes

  • MDN: Non-standard; not part of any specification.
  • Not Deprecated or Experimental on that MDN page—still unsuitable as a cross-browser dependency.
  • Always feature-detect; provide pageY / offsetY fallbacks.
  • Related: layerX, metaKey, clientY, MouseEvent(), Window, JavaScript hub.

Limited / Non-standard Support

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.

Limited Non-standard
Google Chrome May expose layerY (non-standard)
Limited
Mozilla Firefox May expose layerY (non-standard)
Limited
Apple Safari May expose layerY (non-standard)
Limited
Microsoft Edge Chromium-based; non-standard
Limited
Opera Chromium-based; non-standard
Limited
Internet Explorer Legacy exposure possible
Limited
layerY Limited

Bottom line: Non-standard vertical layer coordinate; use standard mouse Y properties for new code.

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.

Continue with metaKey, clientY, Window, or the JavaScript hub.

💡 Best Practices

✅ Do

  • Feature-detect before reading layerY
  • Prefer offsetY / pageY / clientY
  • 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

Key Takeaways

Knowledge Unlocked

Five things to remember about layerY

Non-standard layer Y—learn it, prefer standards.

5
Core concepts
🖱️ 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.

Next: MouseEvent.metaKey

Learn the Meta / Command / Windows key modifier on mouse events.

metaKey →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

5 people found this page helpful