Example 1 — Basic Read
Beginner example for window.scrollX.
console.log(typeof window.scrollX);
console.log(window.scrollX === window.pageXOffset); How It Works
- Step. scrollX aliases pageXOffset.
- Step. Usually 0 until the user scrolls sideways.

window.scrollX is how many CSS pixels the document is scrolled horizontally. pageXOffset is the same value.
Read window.scrollX with no parentheses.
window.scrollX; | Call | What it does |
|---|---|
window.scrollX | Horizontal scroll offset in pixels. |
Window property in browsers. No import required.
| Parameter | Description |
|---|---|
| window.scrollX | Read-only or assignable depending on the property. No function arguments. |
| Return Value | Description |
|---|---|
| * | Horizontal scroll offset in pixels. |
Beginner example for window.scrollX.
console.log(typeof window.scrollX);
console.log(window.scrollX === window.pageXOffset); Beginner example for window.scrollX.
console.log(window.scrollX >= 0); Beginner example for window.scrollX.
console.log("x=" + window.scrollX + ", y=" + window.scrollY); window.scrollX is a standard Window property in browsers.
Available in all modern browsers. Not used in plain Node.js without a DOM.
Bottom line: Safe in browsers. Skip in server-only Node scripts.
Continue through the Window properties list.
CODETOFUN NEWS
Get the latest IT news, programming updates, and technology trends directly on your phone.
Your daily dose of tech, straight to your feed.
9 people found this page helpful