DEV Community

Cover image for How to get the width and height of the window using JavaScript?
MELVIN GEORGE
MELVIN GEORGE

Posted on • Originally published at melvingeorge.me

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

Originally posted here!

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
Enter fullscreen mode Exit fullscreen mode
  • 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 😃.


Top comments (0)