HomeTutorsContact
JavaScript
How to get viewport width and height using JavaScript?
Gulshan Saini
June 09, 2020
1 min

Getting viewport width

To detect interior width of the window in pixels we can use innerWidth property.

window.innerWidth returns width of window including the scrollbar. To exclude scrollbar we need to use the root <html> element’s clientWidth property instead.

Getting viewport height

To detect interior height of the window in pixels we can use innerHeight property.

window.innerHeight returns height of window including the scrollbar. To exclude scrollbar we need to use the root <html> element’s clientHeight property instead.


Tags

#javascript
Previous Article
How to detect color preference based on user settings?

Subscribe to our newsletter!

We'll send you the best of our blog just once a month. We promise.

Related Posts

How to Get Current Date in Human Readable Form in JavaScript?
October 03, 2020
1 min
© 2020, All Rights Reserved.

Quick Links

Advertise with usContact Us

Social Media