JavaScript Window innerWidth Tutorial

In this section, we will learn what the innerWidth property is and how to use it in JavaScript.

JavaScript Window innerWidth Property

The `innerWidth` is a read only property that returns the width of the visual view-port, which is the visible area of the page on the screen. (The content area)

Note: the value of the `innerWidth` property changes if we zoom in or out of a page. This is because we’re basically changing the visible area of a page on the screen.

Note: this property is read-only.

Window innerWidth Property Syntax:

window.innerWidth

Example: JavaScript get window size (width) via innerWidth property

console.log(window.innerWidth);

Output:

As we change the size of the browser, the value of the `innerWidth` can change as well.

Leave a Reply