Window innerWidthand innerHeightProperty
Window Object
Definition and Usage
innerHeight Returns the height of the window's document display area, including the scrollbar height if there is a vertical scrollbar.
innerWidth Returns the width of the window's document display area, including the scrollbar height if there is a horizontal scrollbar.
innerWidth and innerHeight are read-only properties.
Note:UseouterWidth and outerHeightproperties to get the width and height of the browser window.
Syntax
Get the width and height of the document display area:
window.innerWidth window.innerHeight
Set the width and height of the document display area:
window.innerWidth=pixels window.innerHeight=pixels
Browser Support
The numbers in the table indicate the first browser version number that supports the property.
| Property | |||||
|---|---|---|---|---|---|
| innerWidth | 1.0 | 9.0 | 1.0 | 3.0 | 9.0 |
| innerHeight | 1.0 | 9.0 | 1.0 | 3.0 | 9.0 |
Note: IE 8 and earlier IE versions do not support these two properties; you can useclientWidth and clientHeightproperties.
Example
Example
Get the height and width of the window:
Try it yourself »
The following demonstrates the usage of innerWidth, innerHeight, outerWidth, and outerHeight:
Example
Try it yourself »
A practical JavaScript solution (covering all browsers, including IE8 and lower versions):
Example
Try it yourself »
Window Object Other Extensions