How to get the window size in JavaScript
Today we’ll show you how to get the window size in JavaScript. In the previous article, we discussed how to get the screen size in JavaScript.
Checkout more articles on JavaScript
Get the two different types of the window size
1. Get the window outer size
window.outerWidth
Gets the width of the outside of the browser window.
window.outerHeight
Gets the height of the outside of the browser window.
1 2 | const windowOuterWidth = window.outerWidth; // Output: 1109 const windowOuterHeight = window.outerHeight; // Output: 620 |
2. Get the window inner size
window.innerWidth
Gets the width of the content area of the browser window including, if rendered, the vertical scrollbar.
window.innerHeight
Gets the height of the content area of the browser window including, if rendered, the horizontal scrollbar.
1 2 | const windowInnerWidth = window.innerWidth; // Output: 780 const windowInnerHeight = window.innerHeight; // Output: 532 |
I hope you find this article helpful.
Thank you for reading. Happy Coding..!! 🙂