JavaScript MouseEvent y Property

Beginner
⏱️ 8 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
Baseline Widely available
Instance property

What You’ll Learn

MouseEvent.y is a read-only number and an alias for clientY: vertical position inside the viewport. Learn why the short name exists, prove y === clientY, and practice with five try-it labs.

01

Kind

Instance property

02

Returns

Number (CSS px)

03

Status

Baseline Widely available

04

Alias of

clientY

05

Pair with

x / clientX

06

Origin

Viewport top edge

Introduction

Some APIs like short names. event.y is simply another way to read the same viewport Y that event.clientY already gives you. Pair it with event.x (alias of clientX) for a compact viewport point.

JavaScript
document.addEventListener("mousemove", (event) => {
  console.log(event.y);       // same as event.clientY
  console.log(event.clientY); // viewport Y in CSS pixels
});
💡
Beginner tip

MDN one-liner: MouseEvent.y is an alias for MouseEvent.clientY. If you already understand clientY, you already understand y.

Understanding the Property

MDN: the y property is an alias for clientY. That means it is the vertical coordinate within the application’s viewport at which the event occurred—not the document page and not the OS screen.

  • Instance — read event.y in a handler.
  • Number — CSS pixels from the viewport’s top edge.
  • Alias — same value as event.clientY.
  • Read-only — set via constructor options (usually clientY) on synthetic events.

📝 Syntax

JavaScript
const y = mouseEvent.y;

Value

A number in CSS pixels from the top edge of the viewport—identical to mouseEvent.clientY on supporting browsers.

⚖️ y vs Other Y Coordinates

PropertyMeasured fromNotes
yViewport topAlias of clientY
clientYViewport topSame value as y
pageYDocument topIncludes vertical scroll
screenYScreen (monitor) topIndependent of page scroll

Prefer clientY in team code if clarity matters; use y when you want the short CSSOM View names alongside x.

⚡ Quick Reference

GoalCode
Read viewport Yevent.y or event.clientY
Prove aliasevent.y === event.clientY
Viewport point{ x: event.x, y: event.y }
Synthetic clicknew MouseEvent("click", { clientX: 100, clientY: 50 })
MDN statusBaseline Widely available (Apr 2017)

🔍 At a Glance

Four facts about y.

Kind
instance

On the event

Type
number

CSS pixels

Alias
clientY

Same value

Status
baseline

Widely available

Examples Gallery

Examples follow MDN MouseEvent.y and the related clientY behavior. Move the mouse and confirm the alias in the try-it labs.

📚 Getting Started

Read y from live pointer events.

Example 1 — Log x and y

Short names for viewport coordinates on every move.

JavaScript
const log = document.querySelector("#log");

document.addEventListener("mousemove", (e) => {
  log.textContent = `x: ${e.x}, y: ${e.y}`;
});
Try It Yourself

How It Works

e.x / e.y update as the pointer moves. They are viewport coordinates—the same numbers you would get from clientX / clientY.

Example 2 — Prove y === clientY

MDN’s core claim as a one-line check.

JavaScript
document.addEventListener("click", (e) => {
  console.log(e.y);
  console.log(e.clientY);
  console.log(e.y === e.clientY); // true when both are numbers
});
Try It Yourself

How It Works

If the equality check prints true, you have confirmed the alias on this browser for that click.

📈 Synthetic Events, Compare & UI

Construct coordinates, compare systems, move fixed UI.

Example 3 — Synthetic Event: clientY Sets y

Pass clientY in options; read either name afterward.

JavaScript
const event = new MouseEvent("click", {
  clientX: 120,
  clientY: 40,
  bubbles: true
});

console.log(event.clientY); // 40
console.log(event.y);       // 40 (alias)
console.log(event.y === event.clientY); // true
Try It Yourself

How It Works

The MouseEvent() constructor commonly accepts clientX / clientY. Engines that implement the alias then expose the same numbers on x / y.

Example 4 — Compare y, clientY, and pageY

Alias pair vs document coordinate.

JavaScript
document.addEventListener("click", (e) => {
  console.log({
    y: e.y,
    clientY: e.clientY,
    pageY: e.pageY,
    scrollY: window.scrollY
  });
  // y and clientY match; pageY ≈ clientY + scrollY
});
Try It Yourself

How It Works

y and clientY stay locked together. pageY diverges once the document is scrolled vertically.

Example 5 — Position Fixed UI with y

Same pattern as clientY, shorter property names.

JavaScript
const tip = document.querySelector("#tip");

document.addEventListener("mousemove", (e) => {
  tip.style.left = `${e.x + 12}px`;
  tip.style.top = `${e.y + 12}px`;
  tip.textContent = `${e.x}, ${e.y}`;
});
Try It Yourself

How It Works

With position: fixed, left/top are already in viewport space—so x / y map directly, just like clientX / clientY.

🚀 Common Use Cases

  • Compact viewport points: { x: event.x, y: event.y }.
  • Floating tooltips and custom cursors (same as clientY).
  • Teaching that CSSOM View exposes short aliases for client coordinates.
  • Code that already uses x / y naming consistently.
  • Quick equality checks while debugging coordinate systems.

🔧 How It Works

1

Pointer moves or clicks

The browser computes viewport coordinates.

Input
2

MouseEvent stores clientY

Vertical CSS pixels from the viewport’s top edge.

Viewport
3

y aliases that value

Reading event.y returns the same number as clientY.

Alias
4

Use either name

Pick y or clientY; keep the team consistent.

📝 Notes

  • Baseline Widely available (MDN, since April 2017).
  • Not Deprecated, Experimental, or Non-standard — no status banner required.
  • Defined in the CSSOM View Module as an alias of clientY.
  • Related: x, clientY, clientX, MouseEvent(), JavaScript hub.

Universal Browser Support

MouseEvent.y is Baseline Widely available across modern browsers (MDN: since April 2017). Logos use the shared browser-image-sprite.png sprite from this project.

Baseline · Widely available

MouseEvent.y

Short alias for clientY—viewport Y in CSS pixels for mouse events.

Universal Widely available
Google Chrome Full support · Desktop & Mobile
Full support
Mozilla Firefox Full support · Desktop & Mobile
Full support
Apple Safari Full support · macOS & iOS
Full support
Microsoft Edge Full support · Chromium
Full support
Opera Full support · Modern versions
Full support
Internet Explorer Supported in modern IE versions
Full support
y Excellent

Bottom line: Read event.y or event.clientY for viewport Y; they are the same value on supporting browsers.

Conclusion

event.y is the short name for viewport Y—an alias of clientY. Use either property for fixed UI and hit tests; reach for pageY when document scroll matters.

Continue with getModifierState(), x, clientY, or the JavaScript hub.

💡 Best Practices

✅ Do

  • Treat y as identical to clientY
  • Pair with x (or clientX) for a full point
  • Use position: fixed overlays with viewport coordinates
  • Prefer one naming style in a codebase for consistency
  • Pass clientY in synthetic MouseEvent options

❌ Don’t

  • Assume y equals pageY after scrolling
  • Confuse viewport y with screen screenY
  • Mix y and clientY randomly in the same file
  • Use viewport coords for document-absolute markers
  • Mutate event.y on live user events

Key Takeaways

Knowledge Unlocked

Five things to remember about y

Short alias for clientY—viewport vertical position.

5
Core concepts
🔄 02

Alias

of clientY

MDN
📐 03

Viewport

top edge origin

Origin
🔢 04

Number

CSS pixels

Type
🛡️ 05

Baseline

widely available

Status

❓ Frequently Asked Questions

It is a read-only number that is an alias for MouseEvent.clientY: the vertical mouse position in CSS pixels relative to the browser viewport (the visible window area).
No. MDN marks MouseEvent.y as Baseline Widely available (since April 2017). It is not Deprecated, Experimental, or Non-standard, so no status warning banner is needed.
Yes. MDN states that MouseEvent.y is an alias for MouseEvent.clientY. In supporting browsers, event.y === event.clientY for the same event.
Both work. Many tutorials and codebases prefer clientY because the name clearly says “client/viewport.” Use y when you want shorter property names or CSSOM View-style naming next to event.x.
y / clientY are viewport-relative and ignore document scroll. pageY is document-relative and grows when you scroll down.
Pass clientY in MouseEvent options (for example new MouseEvent("click", { clientX: 120, clientY: 40 })). Engines typically expose the same value on event.y as well.
Did you know?

Together, MouseEvent.x and MouseEvent.y give you a tidy { x, y } point in viewport space—the same idea as clientX / clientY, just with shorter CSSOM View names.

Next: MouseEvent.getModifierState()

Learn how to query named modifier keys on mouse events.

getModifierState() →

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