Movatterモバイル変換


[0]ホーム

URL:


MDN Web Docs

Window: innerHeight property

BaselineWidely available

The read-onlyinnerHeight property of theWindow interface returns the interior height of the window in pixels,including the height of the horizontal scroll bar, if present.

The value ofinnerHeight is taken from the height of the window'slayout viewport. The width can be obtained using theinnerWidth property.

Value

An integer value indicating the window's layout viewport height in pixels. The propertyis read only and has no default value.

To change the height of the window, call one of its resize methods, such asresizeTo() orresizeBy().

Usage notes

To obtain the height of the window minus its horizontal scroll bar and any borders, usethe root<html> element'sclientHeight property instead.

BothinnerHeight andinnerWidth are available on any windowor any object that behaves like a window, such as a tab or frame.

Examples

Assuming a frameset

js
console.log(window.innerHeight); // orconsole.log(self.innerHeight);// will log the height of the frame viewport within the framesetconsole.log(parent.innerHeight);// will log the height of the viewport of the closest framesetconsole.log(top.innerHeight);// will log the height of the viewport of the outermost frameset

To change the size of a window, seewindow.resizeBy() andwindow.resizeTo().

To get the outer height of a window, i.e., the height of the whole browser window, seewindow.outerHeight.

Graphical example

The following figure shows the difference betweenouterHeight andinnerHeight.

innerHeight vs. outerHeight illustration

Demo

HTML

html
<p>Resize the browser window to fire the <code>resize</code> event.</p><p>Window height: <span></span></p><p>Window width: <span></span></p>

JavaScript

js
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

Specification
CSSOM View Module
# dom-window-innerheight

Browser compatibility

See also

Help improve MDN

Learn how to contribute.

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp