JavaScript Window innerWidth Property

Beginner
5 min read
Updated: Nov 2026
3 examples
Property

Definition

window.innerWidth is the viewport width in CSS pixels — the area where the page is drawn, not including browser chrome.

Syntax

Read window.innerWidth with no parentheses.

JavaScript
window.innerWidth;
CallWhat it does
window.innerWidthViewport width in CSS pixels.

Window property in browsers. No import required.

Parameters

ParameterDescription
window.innerWidthRead-only or assignable depending on the property. No function arguments.

Return Value

Return ValueDescription
*Viewport width in CSS pixels.

JavaScript Examples

Example 1 — Basic Read

Beginner example for window.innerWidth.

JavaScript
console.log(typeof window.innerWidth);
console.log(window.innerWidth > 0);
Try It Yourself

How It Works

  1. Step. Always a number in a browser window.
  2. Step. Greater than zero for a visible viewport.

Example 2 — Practical Use

Beginner example for window.innerWidth.

JavaScript
const wide = window.innerWidth >= 768;
console.log(wide ? "tablet/desktop width" : "narrow");
Try It Yourself

How It Works

  1. Step. Compare against breakpoints.
  2. Step. Exact output depends on your window size.

Example 3 — Check / Compare

Beginner example for window.innerWidth.

JavaScript
console.log(Math.round(window.innerWidth));
Try It Yourself

How It Works

  1. Step. Round if you need an integer for display.
  2. Step. Your number may differ.

Browser & Runtime Support

window.innerWidth is a standard Window property in browsers.

✓ Browser Window API

window.innerWidth

Available in all modern browsers. Not used in plain Node.js without a DOM.

Browsers Environment
Google Chrome Supported · Desktop & Mobile
Full support
Mozilla Firefox Supported · Desktop & Mobile
Full support
Apple Safari Supported · macOS & iOS
Full support
Microsoft Edge Supported · Chromium
Full support
Internet Explorer No native support · Use a polyfill
Polyfill
Opera Supported · Modern versions
Full support
Samsung Internet Supported · Android
Full support
Bun Supported · JavaScript runtime
Supported
Deno Supported · JavaScript runtime
Supported
Node.js Supported · Server runtime
Supported
Android WebView Supported · Modern WebView
Full support
window.innerWidth Excellent

Bottom line: Safe in browsers. Skip in server-only Node scripts.

Frequently Asked Questions

The width of the layout viewport in CSS pixels.
innerWidth is the page area; outerWidth includes browser UI.
Yes. Listen to the resize event if you need to react.
Open the Window Properties index for every property in this series.

Browse more properties

Continue through the Window properties list.

Next →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

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.

9 people found this page helpful