Example 1 — Basic Read
Beginner example for window.innerWidth.
console.log(typeof window.innerWidth);
console.log(window.innerWidth > 0); How It Works
- Step. Always a number in a browser window.
- Step. Greater than zero for a visible viewport.

window.innerWidth is the viewport width in CSS pixels — the area where the page is drawn, not including browser chrome.
Read window.innerWidth with no parentheses.
window.innerWidth; | Call | What it does |
|---|---|
window.innerWidth | Viewport width in CSS pixels. |
Window property in browsers. No import required.
| Parameter | Description |
|---|---|
| window.innerWidth | Read-only or assignable depending on the property. No function arguments. |
| Return Value | Description |
|---|---|
| * | Viewport width in CSS pixels. |
Beginner example for window.innerWidth.
console.log(typeof window.innerWidth);
console.log(window.innerWidth > 0); Beginner example for window.innerWidth.
const wide = window.innerWidth >= 768;
console.log(wide ? "tablet/desktop width" : "narrow"); Beginner example for window.innerWidth.
console.log(Math.round(window.innerWidth)); window.innerWidth 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