Web/API/Window/innerWidth

From Get docs


The read-only Window property innerWidth returns the interior width of the window in pixels. This includes the width of the vertical scroll bar, if one is present.

More precisely, innerWidth returns the width of the window's layout viewport. The interior height of the window—the height of the layout viewport—can be obtained from the innerHeight property.

Syntax

let intViewportWidth = window.innerWidth;

Value

An integer value indicating the width of the window's layout viewport in pixels. This property is read-only, and has no default value.

To change the window's width, use one of the Window methods for resizing windows, such as resizeBy() or resizeTo().

Usage notes

If you need to obtain the width of the window minus the scrollbar and borders, use the root <html> element's clientWidth property instead.

The innerWidth property is available on any window or object that behaves like a window, such as a frame or tab.

Example

// This will return the width of the viewport
var intFrameWidth = window.innerWidth;

// This will return the width of the frame viewport within a frameset
var intFrameWidth = self.innerWidth;

// This will return the width of the viewport of the closest frameset
var intFramesetWidth = parent.innerWidth;

// This will return the width of the viewport of the outermost frameset
var intOuterFramesetWidth = top.innerWidth;

Specification

Specification Status Comment
CSS Object Model (CSSOM) View ModuleThe definition of 'window.innerWidth' in that specification. Working Draft Initial definition

Browser compatibility

Update compatibility data on GitHub

Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
innerWidth Chrome

Full support 1

Edge

Full support 12

Firefox Full support 1


Full support 1


No support 4 — 24

Notes'

Notes' This property was buggy and could give a wrong value before page load in certain circumstances, see bug 641188.

IE

Full support 9

Opera

Full support 9

Safari

Full support 3

WebView Android

Full support 1

Chrome Android

Full support 18

Firefox Android Full support 4


Full support 4


No support 4 — 24

Notes'

Notes' This property was buggy and could give a wrong value before page load in certain circumstances, see bug 641188.

Opera Android

Full support 10.1

Safari iOS Full support 1

Notes'

Full support 1

Notes'

Notes' This property returns the width of the visual viewport instead of the layout viewport. See this bug for details.

Samsung Internet Android

Full support 1.0

Legend

Full support  
Full support
See implementation notes.'
See implementation notes.


See also