Window: innerHeight property
The read-only innerHeight
property of the Window
interface returns the interior height of the window in pixels, including the height of the horizontal scroll bar, if present.
The value of innerHeight
is taken from the height of the window's layout viewport. The width can be obtained using the innerWidth
property.
Value
An integer value indicating the window's layout viewport height in pixels. The property is read only and has no default value.
To change the width of the window, call one of its resize methods, such as resizeTo()
or resizeBy()
.
Usage notes
To obtain the height of the window minus its horizontal scroll bar and any borders, use the root <html>
element's clientHeight
property instead.
Both innerHeight
and innerWidth
are available on any window or any object that behaves like a window, such as a tab or frame.
Examples
Assuming a frameset
console.log(window.innerHeight);
console.log(self.innerHeight);
console.log(parent.innerHeight);
console.log(top.innerHeight);
To change the size of a window, see window.resizeBy()
and window.resizeTo()
.
To get the outer height of a window, i.e. the height of the whole browser window, see window.outerHeight
.
Graphical example
The following figure shows the difference between outerHeight
and innerHeight
.
Demo
HTML
<p>Resize the browser window to fire the <code>resize</code> event.</p>
<p>Window height: <span id="height"></span></p>
<p>Window width: <span id="width"></span></p>
JavaScript
const heightOutput = document.querySelector("#height");
const widthOutput = document.querySelector("#width");
function updateSize() {
heightOutput.textContent = window.innerHeight;
widthOutput.textContent = window.innerWidth;
}
updateSize();
window.addEventListener("resize", updateSize);
Result
Specifications
Browser compatibility
|
Desktop |
Mobile |
|
Chrome |
Edge |
Firefox |
Internet Explorer |
Opera |
Safari |
WebView Android |
Chrome Android |
Firefox for Android |
Opera Android |
Safari on IOS |
Samsung Internet |
innerHeight |
1 |
12 |
1From version 4 to 24, this property could give a wrong value before page load in certain circumstances (see bug 641188). |
9 |
9 |
3 |
4.4 |
18 |
4Before version 24, this property could give a wrong value before page load in certain circumstances (see bug 641188). |
10.1 |
1This property returns the height of the visual viewport instead of the layout viewport. See this bug for details. |
1.0 |
See also