Get the browser window size in JavaScript
📅July 6, 2022
Today we’ll show you how to get the browser window size in JavaScript. In the previous article, we discussed How to get the screen size using JavaScript.
Here, we will show you the two different methods to get the outer and inner size of the browser.
- JavaScript Window Navigator Object
- One-Liners JavaScript code that you should know
- Calculate number of days between two dates using JavaScript
- How to Copy to Clipboard in JavaScript
- 5 Awesome JavaScript String Tips
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.
const windowOuterWidth = window.outerWidth; // Output: 1109
const windowOuterHeight = window.outerHeight; // Output: 620
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.
const windowInnerWidth = window.innerWidth; // Output: 780
const windowInnerHeight = window.innerHeight; // Output: 532