DOM Window.innerWidth Property
The innerWidth property returns the width of the browser's viewport in pixels. innerHeight returns its height.
Description
The read-only innerWidth and innerHeight properties give the size of the viewport, the visible area of the page, in CSS pixels, including a vertical or horizontal scroll bar if there is one. document.documentElement.clientWidth gives the width without the scroll bar. To react to breakpoints, matchMedia() is usually a better fit than checking these values.
On mobile devices, the values reflect the layout viewport, which depends on the <meta name="viewport"> tag and can change when the on-screen keyboard appears or the browser's toolbars hide. The visualViewport object gives the size of the area actually visible after pinch-zooming.
Reading the size inside a resize handler is the traditional way to respond to window changes, but for layout, CSS media queries and container queries usually do the job without any JavaScript.
Syntax
window.innerWidth
window.innerHeightValue
The width (or height) of the viewport in CSS pixels, including any scroll bar.
Example
Browser Support
The following information will show you the current browser support for the Window.innerWidth property. Hover over a browser icon to see the version that first introduced support for this property.
Desktop





Tablets & Mobile





