• 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:

  • Calculate the size of scrollbar
  • Get the size of an image
  • Check if a node is in the viewport
  • Hexadecimal Color Wheel

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