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.Syntax
var intViewportWidth = window.innerWidth;
Value
intViewportWidth stores the window.innerWidth
property value.
The window.innerWidth
property is read only; it has no default value.
Notes
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.
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;
To change the size of a window, see window.resizeBy
and window.resizeTo
.
Specification
Specification | Status | Comment |
---|---|---|
CSS Object Model (CSSOM) View Module The definition of 'window.innerWidth' in that specification. |
Working Draft | Initial definition |
Browser compatibility
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
Update compatibility data on GitHub
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
innerWidth | Chrome Full support 1 | Edge Full support 12 | Firefox
Full support
1
| IE Full support 9 | Opera Full support 9 | Safari Full support 3 | WebView Android Full support Yes | Chrome Android Full support Yes | Firefox Android
Full support
4
| Opera Android Full support 10.1 | Safari iOS Full support 3 | Samsung Internet Android Full support Yes |
Legend
- Full support
- Full support
- See implementation notes.
- See implementation notes.