Element.prototype.scrollHeight
Returns the total height of an element's content including content not visible on the screen due to overflow
Syntax
element.scrollHeightReturn Value
An integer representing the element's scroll height in pixels
Examples
const el = document.querySelector('.content') as HTMLElement
console.log('Total scrollable height:', el.scrollHeight)function isScrolledToBottom(el: HTMLElement): boolean {
return Math.abs(el.scrollHeight - el.clientHeight - el.scrollTop) < 1
}const chatBox = document.querySelector('.chat') as HTMLElement
chatBox.scrollTop = chatBox.scrollHeightUnderstanding 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
HTMLElement.prototype.clientHeightReturns the inner height of an element in pixels, including padding but excluding borders, margins, and horizontal scrollbars
HTMLElement.prototype.offsetWidthReturns the layout width of an element as an integer, including padding, border, and vertical scrollbar
Element.prototype.scrollIntoViewScrolls the element's ancestor containers so the element is visible to the user
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.