Skip to content

Instantly share code, notes, and snippets.

@Integralist
Last active May 31, 2025 20:20
Show Gist options
  • Save Integralist/1303355 to your computer and use it in GitHub Desktop.
Save Integralist/1303355 to your computer and use it in GitHub Desktop.
Analyze the viewport size #js

It’s possible to analyze the viewport size in JavaScript but it’s a little messy:

  • Most browsers support window.innerWidth and window.innerHeight.

  • But IE6, 7, 8 and 9 in quirks mode require document.body.clientWidth and document.body.clientHeight.

  • All the main browsers support document.documentElement.clientWidth and document.documentElement.clientHeight but it’s inconsistent. Either the window or document dimensions will be returned depending on the browser and mode.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment