Clue Mediator

How to get the window size in JavaScript

๐Ÿ“…June 28, 2021
๐Ÿ—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
  2. Get the window inner 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.

const windowOuterWidth  = window.outerWidth; // Output: 1109
const windowOuterHeight = window.outerHeight; // Output: 620

Window outer size - Clue Mediator

Window outer size - Clue Mediator

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.

const windowInnerWidth  = window.innerWidth; // Output: 780
const windowInnerHeight = window.innerHeight; // Output: 532

Window inner size - Clue Mediator

Window inner size - Clue Mediator

I hope you find this article helpful.
Thank you for reading. Happy Coding..!! ๐Ÿ™‚