Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Window innerWidth and innerHeight properties

Window innerWidth and innerHeight properties

Window Object Reference Window Object


Definition and Usage

innerHeight returns the height of the window's document display area, including the height of the vertical scrollbar if present.

innerWidth returns the width of the window's document display area, including the horizontal scrollbar if present.

innerWidth and innerHeight are read-only properties.

**Note:** Use outerWidth and outerHeight properties 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 that supports this 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 versions do not support these two properties; you can use clientWidth and clientHeight attribute.


Example

Example

to get the height and width of the window:

var

w

=

window

.

innerWidth

;

var

h

=

window

.

innerHeight

;

Try it »

The following demonstrates the use of innerWidth, innerHeight, outerWidth, and outerHeight:

Example

var

txt

=

"

"

;

txt

+=

"

innerWidth:

"

window

.

innerWidth

"

"

;

txt

+=

"

innerHeight:

"

window

.

innerHeight

"

"

;

txt

+=

"

outerWidth:

"

window

.

outerWidth

"

"

;

txt

+=

"

outerHeight:

"

window

.

outerHeight

"

"

;

Try it »

A practical JavaScript solution (covering all browsers, including IE8 and below):

Example

var

w

=

window

.

innerWidth

||

document

.

documentElement

.

clientWidth

||

document

.

body

.

clientWidth

;

var

h

=

window

.

innerHeight

||

document

.

documentElement

.

clientHeight

||

document

.

body

.

clientHeight

;

Try it »


Window Object Reference Window Object