JavaScript MouseEvent screenX Property

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

What You’ll Learn

MouseEvent.screenX is a read-only number: the mouse’s horizontal position relative to the screen (monitor), not the page or the viewport. Learn how it differs from clientX and pageX, multi-monitor behavior, and five try-it labs.

01

Kind

Instance property

02

Returns

Number (CSS px)

03

Status

Baseline Widely available

04

Origin

Screen left edge

05

Pair with

screenY

06

Scroll

Does not affect screenX

Introduction

Sometimes you care about where the pointer sits on the physical display—not where it is inside the scrolled page or the browser chrome. That is screenX (horizontal) and screenY (vertical): coordinates in screen space.

JavaScript
document.addEventListener("mousemove", (event) => {
  console.log(event.screenX); // pixels from screen left
});
💡
Beginner tip

Move the browser window around your monitor: clientX stays tied to the window, while screenX tracks the pointer across the whole display.

Understanding the Property

MDN: screenX provides the horizontal coordinate (offset) of the mouse pointer in screen coordinates. In a multiscreen setup, horizontally aligned screens are treated as one device, so the range of screenX can span their combined width.

  • Instance — read event.screenX in a handler.
  • Number — CSS pixels; a floating-point double.
  • Screen-relative — independent of page scroll.
  • Read-only — set via constructor options on synthetic events only.

📝 Syntax

JavaScript
const x = mouseEvent.screenX;

Value

A double floating-point value in pixels (MDN). Early versions of the specification defined this as an integer; modern engines expose a double for subpixel precision.

⚖️ screenX vs Other X Coordinates

PropertyMeasured fromScroll / window
screenXScreen (monitor) leftIgnores page scroll; follows screen
clientXViewport leftTied to the browser window
pageXDocument leftGrows with horizontal scroll
offsetXTarget padding edgeLocal to the hit element

Mental model: use screenX for display-relative work, clientX for viewport UI, and pageX for document markers. Pair screenX with screenY for a full screen point.

⚡ Quick Reference

GoalCode
Read screen Xevent.screenX
Screen point{ x: event.screenX, y: event.screenY }
Compare systemsscreenX / clientX / pageX
Route by bandsif (e.screenX < 50) …
MDN statusBaseline Widely available (Jul 2015)

🔍 At a Glance

Four facts about screenX.

Kind
instance

On the event

Type
double

CSS pixels

Origin
screen

Left edge = 0

Status
baseline

Widely available

Examples Gallery

Examples follow MDN MouseEvent.screenX. Move the mouse and (if you can) drag the browser window to see screen vs viewport values.

📚 Getting Started

Read screenX / screenY from live pointer events.

Example 1 — Log Screen and Client Coordinates

MDN-style demo: show screen and client positions on mousemove.

JavaScript
const screenLog = document.querySelector("#screen-log");
document.addEventListener("mousemove", logKey);

function logKey(e) {
  screenLog.innerText = `
    Screen X/Y: ${e.screenX}, ${e.screenY}
    Client X/Y: ${e.clientX}, ${e.clientY}`;
}
Try It Yourself

How It Works

Each move prints both coordinate systems. screenX / screenY are monitor-relative; clientX / clientY stay relative to the viewport.

Example 2 — Route an Event by screenX Bands

MDN idea: branch on horizontal screen ranges (teaching pattern).

JavaScript
function checkClickMap(e) {
  if (e.screenX < 50) {
    console.log("left band");
  } else if (e.screenX < 100) {
    console.log("middle band");
  } else {
    console.log("right band");
  }
}

document.addEventListener("click", checkClickMap);
Try It Yourself

How It Works

MDN’s routing example uses absolute screen bands. In real apps you usually prefer viewport or element coordinates; this still shows how screenX can drive simple branches.

📈 Synthetic Events, Compare & Deltas

Construct coordinates, compare systems, estimate window offset.

Example 3 — Synthetic Event with screenX

Useful in tests when you need a known screen point.

JavaScript
const event = new MouseEvent("click", {
  screenX: 640,
  screenY: 360,
  bubbles: true
});

console.log(event.screenX); // 640
console.log(event.screenY); // 360
Try It Yourself

How It Works

Pass numeric screenX / screenY to MouseEvent() when tests assert screen-space positions.

Example 4 — Compare screenX, clientX, pageX

Three X systems on the same move.

JavaScript
document.addEventListener("mousemove", (e) => {
  console.log({
    screenX: e.screenX, // monitor
    clientX: e.clientX, // viewport
    pageX: e.pageX,     // document
    scrollX: window.scrollX
  });
});
Try It Yourself

How It Works

With scrollX === 0, pageX and clientX often match, while screenX is usually larger because it includes the window’s offset on the monitor.

Example 5 — Estimate Window Left with screenX - clientX

Rough teaching math: screen minus viewport hints at the window’s left offset.

JavaScript
document.addEventListener("mousemove", (e) => {
  // Approximate: how far the viewport is from the screen's left
  const approxWindowLeft = e.screenX - e.clientX;
  console.log(approxWindowLeft);
});
Try It Yourself

How It Works

Dragging the window sideways changes screenX - clientX while keeping clientX stable for the same point inside the page. Real apps rarely need this; it is a clear way to feel the difference between the two systems.

🚀 Common Use Cases

  • Debugging pointer position relative to the physical display.
  • Teaching screen vs viewport vs document coordinate systems.
  • Simple screen-band routing demos (as on MDN).
  • Synthetic events in tests with known screenX / screenY.
  • Understanding multi-monitor horizontal ranges.

🔧 How It Works

1

Pointer moves on the display

The OS knows the cursor position in screen pixels.

Input
2

Browser keeps screen coordinates

Also maps to viewport and document for clientX / pageX.

Mapping
3

MouseEvent stores screenX

Your listener reads the horizontal screen coordinate.

Event
4

Use screen coordinates

Compare with clientX / pageX when teaching or debugging.

📝 Notes

  • Baseline Widely available (MDN, since July 2015).
  • Not Deprecated, Experimental, or Non-standard — no status banner required.
  • Horizontally aligned multi-monitor setups can widen the screenX range.
  • Value type is a floating-point double in modern engines.
  • Related: relatedTarget, clientX, pageX, MouseEvent(), Window, JavaScript hub.

Universal Browser Support

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

Reliable screen-relative X for monitor-space pointer positions.

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

Bottom line: Read event.screenX for monitor-space horizontal position; pair with screenY for a full screen point.

Conclusion

event.screenX gives you the horizontal mouse position relative to the screen. Use it when you need display space; reach for clientX for viewport UI and pageX for document markers.

Continue with screenY, clientX, pageX, or the JavaScript hub.

💡 Best Practices

✅ Do

  • Use screenX for screen-space horizontal positions
  • Pair with screenY for a full screen point
  • Compare with clientX / pageX when teaching
  • Expect larger ranges on multi-monitor setups
  • Prefer clientX for most in-page UI

❌ Don’t

  • Confuse screenX with viewport clientX
  • Assume page scroll changes screenX
  • Place absolute page markers with screen coordinates
  • Assume it equals offsetX inside an element
  • Mutate event.screenX on live user events

Key Takeaways

Knowledge Unlocked

Five things to remember about screenX

Screen-relative X that ignores page scroll.

5
Core concepts
🔢 02

Double

CSS pixels

Type
🖥️ 03

Screen

left edge origin

Origin
📈 04

Scroll-free

ignores page scroll

Behavior
🛡️ 05

Baseline

widely available

Status

❓ Frequently Asked Questions

It is a read-only number: the horizontal mouse position in CSS pixels relative to the left edge of the user’s screen (monitor), not the browser window or the document.
No. MDN marks MouseEvent.screenX as Baseline Widely available (since July 2015). It is not Deprecated, Experimental, or Non-standard, so no status warning banner is needed.
clientX is measured from the viewport’s left edge (the visible browser window). screenX is measured from the screen’s left edge. Moving or resizing the window changes how they relate.
pageX is relative to the document and includes horizontal scroll. screenX ignores page scroll and window position relative to the document—it is screen-space.
MDN: in a multiscreen environment, screens aligned horizontally are treated as one device, so screenX can grow across the combined width of those screens.
A double floating-point number of pixels. Early specs defined it as an integer; modern engines expose a double for subpixel precision.
Did you know?

MDN notes that on multi-monitor setups with screens lined up side by side, browsers treat them as one wide device—so screenX can keep climbing past a single monitor’s width as the pointer crosses into the next display.

Next: MouseEvent.screenY

Learn vertical mouse position in screen (monitor) coordinates.

screenY →

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