MouseEvent.offsetY is a read-only number: how far the pointer is from the top padding edge of the element that received the event. Learn when to use it instead of clientY / pageY, how it pairs with offsetX, and five try-it labs.
01
Kind
Instance property
02
Returns
Number (CSS px)
03
Status
Baseline Widely available
04
Origin
Target padding edge
05
Pair with
offsetX
06
Best for
Element-local clicks
Fundamentals
Introduction
Sampling a row on a canvas, placing a pin on a photo, or measuring a click inside a card needs “how far down inside this element?” That is offsetY (vertical), paired with offsetX (horizontal)—coordinates relative to the target’s padding box.
JavaScript
box.addEventListener("click", (event) => {
console.log(event.offsetY); // pixels from the target's top padding edge
});
💡
Beginner tip
Imagine a ruler glued to the top padding edge of the clicked element. Zero is that edge—not the viewport top, and not the document top.
Concept
Understanding the Property
MDN: offsetY provides the offset in the Y coordinate of the mouse pointer between that event and the padding edge of the target node.
Instance — read event.offsetY in a handler.
Number — CSS pixels; a floating-point double.
Target-relative — measured from event.target’s top padding edge.
Read-only — set via constructor options on synthetic events only.
Foundation
📝 Syntax
JavaScript
const y = mouseEvent.offsetY;
Value
A double floating-point value in pixels (MDN). Early versions of the specification defined this as an integer; modern browsers report a floating-point number.
Because the listener is on the box, offsetY is measured from that box’s top padding edge—ideal for element-local vertical tools.
Example 2 — Compare offsetY and clientY
Same click, two coordinate systems: element-local vs viewport.
JavaScript
box.addEventListener("click", (e) => {
console.log({
offsetY: e.offsetY, // relative to the box
clientY: e.clientY, // relative to the viewport
pageY: e.pageY // relative to the document
});
});
MouseEvent.offsetY is Baseline Widely available across modern browsers (MDN: since December 2015). Logos use the shared browser-image-sprite.png sprite from this project.
✓ Baseline · Widely available
MouseEvent.offsetY
Reliable element-local Y from the target padding edge—great for canvas, vertical sliders, and hit boxes.
UniversalWidely available
Google ChromeFull support · Desktop & Mobile
Full support
Mozilla FirefoxFull support · Desktop & Mobile
Full support
Apple SafariFull support · macOS & iOS
Full support
Microsoft EdgeFull support · Chromium
Full support
OperaFull support · Modern versions
Full support
Internet ExplorerSupported in modern IE versions
Full support
offsetYExcellent
Bottom line: Read event.offsetY for target-local vertical position; pair with offsetX for a full local point.
Wrap Up
Conclusion
event.offsetY gives you the vertical mouse position relative to the target element’s top padding edge. Use it for canvas clicks, local markers, and percentage-based vertical controls; reach for clientY when you need viewport space instead.
Use offsetY for element-local vertical hit positions
Pair with offsetX for a full local point
Prefer it over non-standard layerY for new code
Normalize with element height for responsive percentages
Remember the origin is the top padding edge
❌ Don’t
Confuse offsetY with viewport clientY
Assume it equals pageY after scrolling
Ignore borders when mentally mapping the padding edge
Use viewport-fixed UI math with local coordinates
Mutate event.offsetY on live user events
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about offsetY
Element-local Y from the target top padding edge.
5
Core concepts
🖱️01
Instance
on the event
Kind
🔢02
Double
CSS pixels
Type
📐03
Padding edge
target top
Origin
📈04
Local UX
canvas / meters
Use
🛡️05
Baseline
widely available
Status
❓ Frequently Asked Questions
It is a read-only number: the vertical offset of the mouse pointer from the padding edge of the event’s target element, measured in CSS pixels.
No. MDN marks MouseEvent.offsetY as Baseline Widely available (since December 2015). It is not Deprecated, Experimental, or Non-standard, so no status warning banner is needed.
offsetY is measured from the top padding edge of the target node—inside the border, at the start of the padding box. Borders are outside that origin; padding and content are inside.
clientY is relative to the browser viewport. offsetY is relative to the element that received the event (event.target). Moving the same element on the page changes clientY for the same spot on the element, but offsetY stays local to that element.
pageY is relative to the whole document (includes vertical scroll). offsetY stays local to the target element’s padding box and does not grow just because the page scrolled.
A double (floating-point) number in pixels. Early versions of the spec defined it as an integer; modern browsers report a double.
Did you know?
Like offsetX, MDN notes that early versions of the specification defined offsetY as an integer, while today it is a floating-point double. That is why you may see values like 20.5 on high-DPI displays instead of whole numbers only.