JavaScript MouseEvent clientY Property

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

What You’ll Learn

MouseEvent.clientY is a read-only number: the mouse’s vertical position inside the viewport. Learn how it differs from pageY and screenY, why vertical scroll does not change the top-edge rule, how it pairs with clientX, and five try-it labs.

01

Kind

Instance property

02

Returns

Number (CSS px)

03

Status

Baseline Widely available

04

Origin

Viewport top edge

05

Pair with

clientX

06

Scroll

Does not shift origin

Introduction

Together with clientX, clientY answers “how far down is the pointer in the window?” Zero is the top of the visible viewport—not the top of a long scrolled document.

JavaScript
document.addEventListener("mousemove", (event) => {
  console.log(event.clientY); // pixels from viewport top
});
💡
Beginner tip

Imagine a sticky ruler on the browser window. Zero is always the top edge of what you currently see—even after you scroll the page down.

Understanding the Property

MDN: clientY provides the vertical coordinate within the application’s viewport at which the event occurred (as opposed to the coordinate within the page). Clicking the top edge of the viewport always yields clientY of 0, even if the page is scrolled vertically.

  • Instance — read event.clientY in a handler.
  • Number — CSS pixels; often a floating-point double.
  • Viewport-relative — not document scroll, not the OS screen.
  • Read-only — set via constructor options on synthetic events only.

📝 Syntax

JavaScript
const y = mouseEvent.clientY;

Value

A number (double) in CSS pixels from the top edge of the viewport.

⚖️ clientY vs Other Y Coordinates

PropertyMeasured fromScroll effect
clientYViewport topOrigin stays fixed to the window
pageYDocument topGrows when you scroll down
screenYScreen (monitor) topIndependent of page scroll
offsetYTarget element padding edgeLocal to the hit element

Pair clientY with clientX for a full viewport point. For document-relative placement on a tall page, prefer pageX / pageY.

⚡ Quick Reference

GoalCode
Read viewport Yevent.clientY
Viewport point{ x: event.clientX, y: event.clientY }
Fixed UI at pointerel.style.top = event.clientY + "px"
Synthetic clicknew MouseEvent("click", { clientX: 100, clientY: 50 })
MDN statusBaseline Widely available (Jul 2015)

🔍 At a Glance

Four facts about clientY.

Kind
instance

On the event

Type
number

CSS pixels

Origin
viewport

Top edge = 0

Status
baseline

Widely available

Examples Gallery

Examples follow MDN MouseEvent.clientY. Move the mouse and compare vertical coordinate systems in the try-it labs.

📚 Getting Started

Read clientY from live pointer events.

Example 1 — Log Client and Screen Coordinates

MDN-style: print positions on every mousemove.

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

document.addEventListener("mousemove", (e) => {
  screenLog.innerText = `
    Screen X/Y: ${e.screenX}, ${e.screenY}
    Client X/Y: ${e.clientX}, ${e.clientY}`;
});
Try It Yourself

How It Works

clientY updates as the pointer moves down the window. screenY uses the whole monitor instead.

Example 2 — Top Edge Stays 0 After Scroll

MDN insight: viewport top is always client Y of zero.

JavaScript
// Tall page + vertical scroll — click near the top of the *window*
document.addEventListener("click", (e) => {
  console.log("clientY:", e.clientY);
  console.log("pageY:", e.pageY);
  // Near viewport top: clientY ≈ 0 even if pageY is large after scrolling
});
Try It Yourself

How It Works

After scrolling, a click near the window’s top still reports a small clientY, while pageY includes the scroll offset.

📈 Synthetic Events, pageY & UI Follow

Construct coordinates, compare systems, move fixed UI.

Example 3 — Synthetic Event with clientY

Useful in tests when you need a known viewport point.

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

console.log(event.clientX); // 120
console.log(event.clientY); // 40
Try It Yourself

How It Works

Pass numeric clientX / clientY to MouseEvent(). Some engines require numbers for these fields.

Example 4 — Compare clientY and pageY

When scrollY is zero they often match; after scrolling they diverge.

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

How It Works

A useful mental model: pageY ≈ clientY + window.scrollY (and similarly for X). Prefer the property that matches your layout coordinate system.

Example 5 — Position Fixed UI with clientY

Great for floating labels that stick to the viewport.

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

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

How It Works

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

🚀 Common Use Cases

  • Floating tooltips and custom cursors that track the pointer in the window.
  • Measuring how far down the pointer is for viewport-fixed chrome.
  • Logging vertical position while teaching coordinate systems.
  • Synthetic events in tests with known clientX / clientY.
  • Choosing between viewport (client*) and document (page*) layouts.

🔧 How It Works

1

Pointer moves or clicks

OS reports a position relative to the display.

Input
2

Browser maps to the viewport

Converts into CSS pixels from the window’s top edge.

Viewport
3

MouseEvent stores clientY

Your listener reads the vertical viewport coordinate.

Event
4

Drive fixed UI or hit tests

Use with clientX for a full viewport point.

📝 Notes

  • Baseline Widely available (MDN, since July 2015).
  • Not Deprecated, Experimental, or Non-standard — no status banner required.
  • Top edge of the viewport ⇒ clientY === 0, regardless of vertical scroll.
  • Related: clientX, ctrlKey, buttons, MouseEvent(), Window, JavaScript hub.

Universal Browser Support

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

Baseline · Widely available

MouseEvent.clientY

Vertical mouse position in viewport CSS pixels—pair with clientX for fixed UI that follows the pointer.

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
clientY Excellent

Bottom line: Read event.clientY for viewport Y; use pageY when you need document coordinates.

Conclusion

event.clientY is the pointer’s Y inside the viewport. Use it with clientX for window-relative UI, and switch to pageY when the document scroll position matters.

Continue with ctrlKey, clientX, MouseEvent(), or the JavaScript hub.

💡 Best Practices

✅ Do

  • Use clientY for position: fixed overlays
  • Pair with clientX for a full point
  • Prefer pageY for document-absolute markers
  • Pass numbers in synthetic MouseEvent options
  • Remember top viewport edge → 0

❌ Don’t

  • Assume clientY equals pageY after scrolling
  • Confuse viewport coords with screenY
  • Forget high-DPI can yield fractional pixel values
  • Use clientY alone when layout is scrolled document space
  • Expect synthetic coords to move the real OS cursor

Key Takeaways

Knowledge Unlocked

Five things to remember about clientY

Viewport Y for every mouse event.

5
Core concepts
📐 02

Viewport

not the page

Origin
🔢 03

Number

CSS pixels

Type
⚖️ 04

≠ pageY

scroll differs

Compare
🛡️ 05

Baseline

widely available

Status

❓ Frequently Asked Questions

It is a read-only number: the vertical mouse position in CSS pixels relative to the browser viewport (the visible window area), not the full page document.
No. MDN marks MouseEvent.clientY as Baseline Widely available (since July 2015). It is not Deprecated, Experimental, or Non-standard, so no status warning banner is needed.
clientY is measured from the top edge of the viewport and ignores page scroll. pageY is measured from the top of the document and grows when you scroll down.
screenY is relative to the entire screen (monitor). clientY is relative to the browser viewport only.
Because the viewport’s top edge is always Y = 0 for client coordinates. Scrolling the document does not move that edge, so clientY stays based on what you see in the window.
Pass clientY (and usually clientX) in MouseEvent options, for example new MouseEvent("click", { clientX: 120, clientY: 40 }).
Did you know?

MDN’s quick test for clientY mirrors clientX: click the top edge of the browser window and you get 0 whether or not the page is scrolled vertically. That is the fastest way to remember viewport vs page Y.

Next: MouseEvent.ctrlKey

Learn the Control modifier boolean on mouse events.

ctrlKey →

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