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.