How to get the width and height of the window using JavaScript?

January 28, 2021 - 1 min read

To get the width and height of the window, you can use the innerWidth property and innerHeight property respectively in the global window object in JavaScript.

// window height
const height = window.innerHeight;

// window width
const width = window.innerWidth;

console.log(height, width); // 711 1440
  • Both the properties return the pixel value in the Number type.

See this example live in JSBin.

Feel free to share if you found this useful 😃.