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

Published January 28, 2021

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 😃.

Share on: Facebook Twitter