How to get the screen size (width, height) in JavaScript
Learn, how to get the device width and height in JavaScript
Using availHeight and availWidth
We can use the screen.availWidth
and screen.availHeight
properties to get the screen size of a device in pixels.
Example:
window.screen.availWidth; // 1440
window.screen.availWidth; // 877
Note: The availWidth, availHeight properties excludes the device taskbar.
If you want to get the total width and height of the user’s screen including taskbar, you can use the screen.width
and screen.height
properties.
window.screen.width; // 1440
window.screen.height; // 900