JavaScript MouseEvent pageY Property

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

What You’ll Learn

MouseEvent.pageY is a read-only number: the mouse’s vertical position relative to the entire document, including scrolled-away content. Learn how it differs from clientY and offsetY, the scroll formula, and five try-it labs.

01

Kind

Instance property

02

Returns

Number (CSS px)

03

Status

Baseline Widely available

04

Origin

Document top edge

05

Pair with

pageX

06

Scroll

Included in the value

Introduction

Absolute pins on a tall article, annotations down a long page, and document-space hit maps need “how far from the top of the page?” That is pageY (vertical), paired with pageX (horizontal)—coordinates relative to the whole document.

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

Same idea as pageX: if 200px of the top is scrolled away and you click 100px from the viewport’s top edge, pageY is about 300.

Understanding the Property

MDN: pageY returns the Y (vertical) coordinate (in pixels) at which the mouse was clicked, relative to the top edge of the entire document. This includes any portion of the document not currently visible. MDN also points to pageX for the fuller coordinate-system explanation.

  • Instance — read event.pageY in a handler.
  • Number — CSS pixels; a floating-point double.
  • Document-relative — includes vertical scroll.
  • Read-only — set via constructor options on synthetic events only.

📝 Syntax

JavaScript
const y = mouseEvent.pageY;

Value

A double floating-point value in pixels (MDN) from the top edge of the document, regardless of scrolling or viewport positioning.

⚖️ pageY vs Other Y Coordinates

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

Mental model: pageY ≈ clientY + window.scrollY. Pair pageY with pageX for a full document point.

⚡ Quick Reference

GoalCode
Read document Yevent.pageY
Document point{ x: event.pageX, y: event.pageY }
Relate to viewportpageY ≈ clientY + scrollY
Absolute markerel.style.top = event.pageY + "px"
MDN statusBaseline Widely available (Jul 2015)

🔍 At a Glance

Four facts about pageY.

Kind
instance

On the event

Type
double

CSS pixels

Origin
document

Top edge = 0

Status
baseline

Widely available

Examples Gallery

Examples follow MDN MouseEvent.pageY (and the fuller coordinate notes on pageX). Move the mouse and scroll vertically in the try-it labs.

📚 Getting Started

Read pageX / pageY from live pointer events.

Example 1 — Show Position Relative to Page Origin

MDN-style (from the pageX demo): update labels on mousemove.

JavaScript
const box = document.querySelector(".box");
const pageXEl = document.getElementById("x");
const pageYEl = document.getElementById("y");

function updateDisplay(event) {
  pageXEl.innerText = event.pageX;
  pageYEl.innerText = event.pageY;
}

box.addEventListener("mousemove", updateDisplay);
box.addEventListener("mouseenter", updateDisplay);
box.addEventListener("mouseleave", updateDisplay);
Try It Yourself

How It Works

Each move updates both document coordinates. pageY is the vertical half of that page-origin pair.

Example 2 — Scroll Adds to pageY

Vertical twin of the pageX scroll insight.

JavaScript
// Tall page + vertical scroll — click near the top of the *window*
document.addEventListener("click", (e) => {
  console.log("clientY:", e.clientY);
  console.log("scrollY:", window.scrollY);
  console.log("pageY:", e.pageY);
  // Often: pageY ≈ clientY + scrollY
  // Example: scrollY 200 + clientY 100 → pageY 300
});
Try It Yourself

How It Works

clientY stays small near the window’s top edge; pageY adds the vertical scroll distance.

📈 Synthetic Events, Compare & Markers

Construct coordinates, compare systems, place absolute markers.

Example 3 — Synthetic Event with pageY

Useful in tests when you need a known document point.

JavaScript
const event = new MouseEvent("click", {
  pageX: 320,
  pageY: 80,
  bubbles: true
});

console.log(event.pageX); // 320
console.log(event.pageY); // 80
Try It Yourself

How It Works

Pass numeric pageX / pageY to MouseEvent() when tests assert document-space positions.

Example 4 — Compare pageY, clientY, offsetY

Three Y systems on the same click.

JavaScript
box.addEventListener("click", (e) => {
  console.log({
    pageY: e.pageY,     // document
    clientY: e.clientY, // viewport
    offsetY: e.offsetY, // target padding edge
    scrollY: window.scrollY
  });
});
Try It Yourself

How It Works

With scrollY === 0, pageY and clientY often match; offsetY stays local to the box.

Example 5 — Place an Absolute Marker with pageY

Document-space pins stay correct after vertical scroll.

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

document.addEventListener("click", (e) => {
  // pin { position: absolute } on the document/body
  pin.style.left = `${e.pageX}px`;
  pin.style.top = `${e.pageY}px`;
});
Try It Yourself

How It Works

With position: absolute relative to the document, top maps to pageY. For fixed viewport UI, prefer clientY instead.

🚀 Common Use Cases

  • Absolute markers and annotations on tall scrolled pages.
  • Document-space hit maps and click heatmaps.
  • Teaching the difference between viewport and document coordinates.
  • Synthetic events in tests with known pageX / pageY.
  • Layouts that use position: absolute in document space.

🔧 How It Works

1

Pointer clicks or moves

OS reports a position relative to the display.

Input
2

Browser maps to the document

Adds vertical scroll so Y is from the page’s top edge.

Document
3

MouseEvent stores pageY

Your listener reads the vertical document coordinate.

Event
4

Use document coordinates

Place absolute UI or compare with clientY + scrollY.

📝 Notes

  • Baseline Widely available (MDN, since July 2015).
  • Not Deprecated, Experimental, or Non-standard — no status banner required.
  • Includes any portion of the document not currently visible (vertical scroll).
  • Value type is a floating-point double (MDN).
  • Related: pageX, clientY, offsetY, MouseEvent(), Window, JavaScript hub.

Universal Browser Support

MouseEvent.pageY 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.pageY

Reliable document-relative Y including vertical scroll—great for absolute page markers.

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

Bottom line: Read event.pageY for document-space vertical position; pair with pageX for a full document point.

Conclusion

event.pageY gives you the vertical mouse position relative to the entire document, including scrolled content. Use it for absolute page markers; reach for clientY for viewport UI and offsetY for element-local clicks.

Continue with pageX, clientY, relatedTarget, or the JavaScript hub.

💡 Best Practices

✅ Do

  • Use pageY for document-space vertical positions
  • Pair with pageX for a full document point
  • Remember pageY ≈ clientY + scrollY
  • Use absolute positioning when placing page markers
  • Prefer clientY for position: fixed UI

❌ Don’t

  • Confuse pageY with viewport clientY
  • Ignore vertical scroll when debugging large pageY values
  • Use page coordinates for fixed tooltips without converting
  • Assume it equals offsetY inside an element
  • Mutate event.pageY on live user events

Key Takeaways

Knowledge Unlocked

Five things to remember about pageY

Document-relative Y that includes vertical scroll.

5
Core concepts
🔢 02

Double

CSS pixels

Type
📄 03

Document

top edge origin

Origin
📈 04

Scroll-aware

+ scrollY

Math
🛡️ 05

Baseline

widely available

Status

❓ Frequently Asked Questions

It is a read-only number: the vertical mouse position in CSS pixels relative to the top edge of the entire document, including any part of the page that is scrolled out of view.
No. MDN marks MouseEvent.pageY as Baseline Widely available (since July 2015). It is not Deprecated, Experimental, or Non-standard, so no status warning banner is needed.
pageY includes vertical scroll. If 200px of the top is scrolled away and you click 100px from the viewport’s top edge, pageY is about 300—the same idea as pageX for the horizontal axis.
clientY is relative to the viewport (window) and ignores document scroll. pageY is relative to the document and grows when you scroll down. Often: pageY ≈ clientY + window.scrollY.
offsetY is relative to the target element’s top padding edge. pageY is relative to the whole document. Use offsetY for clicks inside a box; use pageY for markers on a tall scrolled page.
A double floating-point value in pixels (MDN). Pair it with pageX for a full document point.
Did you know?

MDN’s pageY page is short on purpose: it points you to pageX for the deeper coordinate-system story. Vertically, the same scroll-aware rule applies—pageY always measures from the document top, not the window top.

Next: MouseEvent.relatedTarget

Learn the secondary EventTarget for mouse enter/leave transitions.

relatedTarget →

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