Element

Element.prototype.scrollHeight

Returns the total height of an element's content including content not visible on the screen due to overflow

Syntax

JavaScript
element.scrollHeight

Return Value

An integer representing the element's scroll height in pixels

Examples

Basic Usage
const el = document.querySelector('.content') as HTMLElement
console.log('Total scrollable height:', el.scrollHeight)
Practical Example
function isScrolledToBottom(el: HTMLElement): boolean {
  return Math.abs(el.scrollHeight - el.clientHeight - el.scrollTop) < 1
}
Advanced Usage
const chatBox = document.querySelector('.chat') as HTMLElement
chatBox.scrollTop = chatBox.scrollHeight

Understanding Element.prototype.scrollHeight

The Element.prototype.scrollHeight method in JavaScript returns the total height of an element's content including content not visible on the screen due to overflow. It belongs to the Element object and is one of the most widely used methods for working with element values in modern JavaScript and TypeScript applications.

The method signature is element.scrollHeight. When called, it returns an integer representing the element's scroll height in pixels. Understanding when and how to use scrollHeight() helps you write more expressive, readable code.

Common use cases for Element.prototype.scrollHeight include data transformation, input validation, API response processing, and building reusable utility functions. It works well alongside related methods like dom-clientheight, dom-offsetwidth, dom-scrollintoview, enabling you to chain operations together for complex data manipulation pipelines.

Browser support for Element.prototype.scrollHeight is excellent across all modern browsers including Chrome, Firefox, Safari, and Edge. It is also fully supported in Node.js and Deno. For older environments, transpilation with Babel or a polyfill may be needed.

Browser Compatibility

Supported in all modern browsers (Chrome, Firefox, Safari, Edge) and Node.js. Part of the ECMAScript standard.

Related Methods

More Element Methods

Other methods in the Element object

Related Tools

More Element Methods

Explore JavaScript Methods

Browse our complete reference of 410 JavaScript methods with syntax, examples, and explanations.