JavaScript Element scrollHeight Property

Beginner
⏱️ 11 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
Baseline
Instance property

What You’ll Learn

Element.scrollHeight is a read-only instance property that measures the full height of an element’s content, including hidden overflow. Learn how it differs from clientHeight, how to detect vertical overflow, how to check whether a user scrolled to the bottom, and how to use it safely—with five examples and try-it labs.

01

Kind

Instance property

02

Access

Read-only

03

Type

Integer (pixels)

04

Includes

Padding & overflow

05

Status

Baseline widely

06

Pairs with

clientHeight, scrollTop

Introduction

When a box has more content than fits in its visible area, the extra text is hidden behind a scrollbar. scrollHeight tells you how tall the full content is, not just the part you can currently see.

That makes it useful for chat windows, terms-and-conditions boxes, expandable panels, and any UI where you need to know whether content overflows or whether the user reached the end.

JavaScript
const box = document.getElementById("notes");
console.log(box.scrollHeight);
💡
Beginner tip

Think of scrollHeight as “how tall would this box need to be to show all content without scrolling vertically?”

Understanding the Property

MDN: the read-only scrollHeight property is a measurement of the height of an element’s content, including content not visible on the screen due to overflow.

  • Read-only — use it to measure, not assign.
  • Includes padding — measured like clientHeight.
  • Excludes border and margin — and horizontal scrollbars.
  • Equals clientHeight when content fits — no vertical overflow needed.

📝 Syntax

JavaScript
scrollHeight

Value

An integer representing the total content height in CSS pixels.

ItemDetail
TypeInteger (pixels)
AccessRead-only property
IncludesPadding and hidden overflow content
ExcludesBorder, margin, horizontal scrollbar
RelatedclientHeight, offsetHeight, scrollTop
⚠️
Rounded values

scrollHeight and clientHeight are rounded, while scrollTop can contain decimals. Use a small threshold when checking whether the user reached the bottom.

📋 MDN Scroll-to-Bottom Check

MDN recommends this threshold pattern because exact equality can fail when scrollTop contains decimals:

JavaScript
function isRead(element) {
  return (
    Math.abs(element.scrollHeight - element.clientHeight - element.scrollTop) <= 1
  );
}

Related learning: scrollTop, clientHeight, and overflow detection with scrollHeight > clientHeight.

⚡ Quick Reference

GoalCode / note
Read full content heightel.scrollHeight
Visible inner heightel.clientHeight
Detect vertical overflowel.scrollHeight > el.clientHeight
Scrolled to bottomMath.abs(el.scrollHeight - el.clientHeight - el.scrollTop) <= 1
Content fitsel.scrollHeight === el.clientHeight
MDN statusBaseline Widely available

🔍 At a Glance

Four facts about Element.scrollHeight.

Kind
get only

Instance

Type
integer

Pixels

Measures
overflow

Full content

Baseline
widely

Jul 2015+

Examples Gallery

Examples follow MDN Element: scrollHeight. Labs use scrollable boxes so you can compare visible height with full content height.

📚 Getting Started

Start by reading the full content height of a scrollable element.

Example 1 — Read scrollHeight

Measure the total height of content inside a scrollable box.

JavaScript
const box = document.getElementById("notes");
console.log(box.scrollHeight);
Try It Yourself

How It Works

scrollHeight counts all content, including the part hidden below the visible area.

📈 Compare, Overflow & Bottom Detection

See how scrollHeight differs from clientHeight and powers common scroll checks.

Example 2 — Compare with clientHeight

Visible height and full content height are often different in overflow boxes.

JavaScript
const box = document.getElementById("notes");
console.log({
  scrollHeight: box.scrollHeight,
  clientHeight: box.clientHeight
});
Try It Yourself

How It Works

clientHeight is what you see. scrollHeight is the full content height needed to avoid vertical scrolling.

Example 3 — Detect Vertical Overflow

MDN’s overflow helper compares the two heights.

JavaScript
function isOverflowing(element) {
  return element.scrollHeight > element.clientHeight;
}

const box = document.getElementById("notes");
console.log(isOverflowing(box));
Try It Yourself

How It Works

If scrollHeight is larger, the content does not fully fit in the visible area.

Example 4 — Check Scrolled to Bottom

Use MDN’s threshold pattern to detect when the user reached the end.

JavaScript
function isRead(element) {
  return (
    Math.abs(element.scrollHeight - element.clientHeight - element.scrollTop) <= 1
  );
}

const box = document.getElementById("terms");
box.scrollTop = box.scrollHeight;
console.log(isRead(box));
Try It Yourself

How It Works

The threshold avoids rounding issues between scrollTop and the rounded height values.

Example 5 — Support Snapshot

Feature-detect and remember the measurement rules.

JavaScript
console.log({
  supported: "scrollHeight" in Element.prototype,
  returns: "integer pixels",
  includes: "padding and hidden overflow",
  status: "Baseline Widely available (MDN)"
});
Try It Yourself

How It Works

Safe to use widely. It is one of the core layout measurement properties for scrollable UI.

🚀 Common Use Cases

  • Detecting whether a message list, feed, or panel has more content below.
  • Checking whether a user scrolled through terms-and-conditions text.
  • Auto-growing text areas or chat boxes based on content height.
  • Comparing visible and full content height before showing a “scroll down” hint.
  • Building scroll progress indicators with scrollTop and clientHeight.

🔧 How It Works

1

Browser measures all content

Visible text and hidden overflow are both counted.

Layout
2

Padding is included

The measurement follows the same rules as clientHeight.

Box model
3

Returns an integer height

You read the value with element.scrollHeight.

Read
4

Compare with clientHeight and scrollTop

Those comparisons power overflow checks and bottom-of-scroll detection.

📝 Notes

  • Not Deprecated, Experimental, or Non-standard on MDN (Baseline Widely available).
  • Returns an integer, while scrollTop may contain decimals.
  • Does not include border, margin, or a horizontal scrollbar.
  • Related: clientHeight, offsetHeight, scrollTop, role, JavaScript hub.

Browser Support

Element.scrollHeight is Baseline Widely available (MDN: across browsers since July 2015). Logos use the shared browser-image-sprite.png sprite from this project.

Baseline Widely available

Element.scrollHeight

Read-only — returns the full content height in pixels, including hidden overflow.

Baseline Widely available
Google Chrome Supported
Yes
Microsoft Edge Supported
Yes
Mozilla Firefox Supported
Yes
Apple Safari Supported
Yes
Opera Supported
Yes
Internet Explorer Supported
Yes
scrollHeight Baseline

Bottom line: Use scrollHeight to measure full content height, detect overflow, and build reliable scroll-to-bottom checks with clientHeight and scrollTop.

Conclusion

scrollHeight is the full-content height measurement behind many scroll-based UI patterns. It includes hidden overflow, works with clientHeight, and pairs naturally with scrollTop for bottom detection.

Continue with role, previousElementSibling, or the JavaScript hub.

💡 Best Practices

✅ Do

  • Compare scrollHeight with clientHeight for overflow checks
  • Use a threshold when testing for bottom-of-scroll
  • Re-measure after content or styles change
  • Pair with scrollTop for progress and read-state logic
  • Test on real scrollable containers, not only the page body

❌ Don’t

  • Assume exact equality with scrollTop will always work
  • Confuse scrollHeight with offsetHeight
  • Forget that border and margin are excluded
  • Assign el.scrollHeight = ... (read-only)
  • Measure once and expect the value to stay fixed forever

Key Takeaways

Knowledge Unlocked

Five things to remember about scrollHeight

Read-only integer height for all content, including hidden overflow.

5
Core concepts
📝02

integer

pixels

Type
🔍03

Full content

includes overflow

Use
04

Baseline

widely available

Status
🎯05

Use threshold

for bottom checks

Tip

❓ Frequently Asked Questions

It returns the total height of an element's content, including content that is not visible because of overflow. It is a read-only measurement in pixels.
No. MDN marks Element.scrollHeight as Baseline Widely available (since July 2015). It is not Deprecated, Experimental, or Non-standard.
clientHeight is the visible inner height of the element. scrollHeight is the full content height needed to show everything without a vertical scrollbar. When content fits, they are usually equal.
Yes. Like clientHeight, scrollHeight includes padding but not border, margin, or a horizontal scrollbar.
Compare scrollHeight and clientHeight. If scrollHeight is greater than clientHeight, the content is overflowing vertically.
Use a threshold check because scrollTop can contain decimals: Math.abs(element.scrollHeight - element.clientHeight - element.scrollTop) <= 1.
Did you know?

MDN’s “read the text before agreeing” demo works because scrollHeight, clientHeight, and scrollTop together tell you whether the user reached the bottom of a scrollable box.

Previous: role

Learn how Element.role reflects the explicit ARIA role attribute.

← role

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

5 people found this page helpful