# Check if user scrolls to the bottom of the page

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

Canonical: https://1loc.dev/dom/check-if-user-scrolls-to-the-bottom-of-the-page/
Version: 1.0.0
Runtime: JavaScript · modern browsers (DOM)
Verification: Usage lines executed in headless Chromium against the fixture markup; no external services
Updated: 2026-10-28

## Implementation

```javascript
function isAtBottom(tolerance = 1) { const { scrollHeight, clientHeight } = document.documentElement; return scrollHeight - clientHeight - window.scrollY <= tolerance; }
```

## Usage

Markup:

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

Script:

```javascript
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.

## 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 does not validate its arguments. Add checks where it receives untrusted input.

## Source and license

Original: https://github.com/phuocng/1loc/blob/14b481cf60dff1620ab1bb99a43b1f68068cdd9b/contents/check-if-user-scrolls-to-the-bottom-of-the-page.mdx
Author: Nguyen Huu Phuoc and original contributors
Contributors: See original repository history
Source commit: 14b481cf60dff1620ab1bb99a43b1f68068cdd9b
Copyright (c) 2020 phuoc-ng
License: MIT — https://1loc.dev/licenses/
Maintainer: Oveyon
Modifications: Allows a 1 px tolerance for fractional scroll positions. Executed in Chromium. Original MDX retained as inert source evidence.
