Check if user scrolls to the bottom of the page

True when the viewport has reached the end of the page.

JavaScriptBrowser · DOM Version 1.0.0 · MIT · .md

check-if-user-scrolls-to-the-bottom-of-the-page.js
function isAtBottom(tolerance = 1) { const { scrollHeight, clientHeight } = document.documentElement; return scrollHeight - clientHeight - window.scrollY <= tolerance; }

Usage

Markup

fixture.html
<div style="height: 3000px"></div>

Script

usage.js
isAtBottom(); // → false
window.scrollTo(0, document.documentElement.scrollHeight);
isAtBottom(); // → true

Lines marked → were executed in headless Chromium against the markup above, and each result was compared with the value shown. Lines marked e.g. are illustrative.

Know the limits

  • A 1 px tolerance absorbs fractional scroll positions on zoomed and high-density screens, where the original’s exact comparison could stay false at the bottom.
  • To load more content, an IntersectionObserver on a sentinel element avoids checking on every scroll event.

The function above is the code the usage lines run. It does not validate its arguments; add checks where it receives untrusted input.

Source & maintenance

Based on Check if user scrolls to the bottom of the page from the original 1loc collection by Nguyen Huu Phuoc. Copyright (c) 2020 phuoc-ng. MIT licensed.

Allows a 1 px tolerance for fractional scroll positions. Executed in Chromium. Original MDX retained as inert source evidence.

Maintained by Oveyon. Source commit: 14b481cf60df. Read the license.

Usage lines executed in headless Chromium against the fixture markup; no external services · reviewed October 28, 2026.

Keep exploring

Type two or more characters. Try “duplicate”, “webhook” or “retry”.