Skip to main content Accessibility Feedback

The Viewport

Viewport Height

There are two methods to get the viewport height: window.innerHeight and document.documentElement.clientHeight. The former is more accurate. The latter has better browser support.

To get the best of both worlds, try innerHeight first, and fallback to clientHeight if not supported.

var viewportHeight = window.innerHeight || document.documentElement.clientHeight;

Works in all modern browsers, and IE9+. You can extend support back further with polyfills.