• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
JavaScriptSource

JavaScriptSource

Search 5,000+ Free JavaScript Snippets

  • Home
  • Browse Snippets
    • Addon
    • Ajax
    • Buttons
    • Cookies
    • CSS
    • Featured
    • Forms
    • Games
    • Generators
    • Image Effects
    • Math Related
    • Miscellaneous
    • Multimedia
    • Navigation
    • Page Details
    • Passwords
    • Text Effects
    • Time & Date
    • User Details
Home / Page Details / Get the height of the viewport

Get the height of the viewport

Get the height of the viewport

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;

Source

https://vanillajstoolkit.com/reference/viewport/viewport-height/

Page Details

Related Snippets:

  • How To Get The Current URL In JavaScript
  • Calculate the size of scrollbar
  • Check If the Document is Ready
  • Get all URL parameters from a query string

Primary Sidebar

Popular Posts

Story Generator

IP Grabber – get a users IP address with JavaScript

Simple Calendar

Remove Ads

Astrological Calculator

Copyright © 2025 JavaScriptSource.com

  • About
  • Privacy Policy
  • FAQ
  • Jobs For Developers