We're looking for a user researcher to understand the needs of developers and designers. Is this you or someone you know? Check out the post: https://mzl.la/2IGzdXS

Width (in pixels) of the browser window viewport including, if rendered, the vertical scrollbar.

Note: If you use nsIDOMWindowUtils.setCSSViewport() to set the virtual window size for page layout purposes, the value returned by this property corresponds to the viewport width set using that method.


var intViewportWidth = window.innerWidth;


intViewportWidth stores the window.innerWidth property value.

The window.innerWidth property is read only; it has no default value.


The innerWidth property is supported in any window object like a window, a frame, a frameset, or a secondary window.

There is an algorithm to obtain the width of the viewport excluding, if rendered, the vertical scrollbar.


// 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;

To change the size of a window, see window.resizeBy and window.resizeTo.


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

Browser compatibility

We're converting our compatibility data into a machine-readable JSON format. This compatibility table still uses the old format, because we haven't yet converted the data it contains. Find out how you can help!

Feature Chrome Edge Firefox (Gecko) Internet Explorer Opera Safari
Basic support 1 (Yes) 1.0 (1.7 or earlier)[1] 9 9 3
Feature Android Edge Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support 1 (Yes) 1.0 (1.0)[1] 9 9 3

[1] From Firefox 4 to 24, this property was buggy and could give a wrong value before page load on certain circumstances, see bug 641188.

See also

Document Tags and Contributors

Last updated by: libbymc,