Element.scrollTop gets or sets how far an element’s content is scrolled vertically from its top edge, in CSS pixels. A positive value means the content has moved down (MDN).
Read the notes below before you get or set this property. Prefer feature detection when support is limited.
Syntax
Use el.scrollTop. Start with this line.
JavaScript
element.scrollTop
Call
What it does
element.scrollTop
Primary signature.
Built into the browser. Read or assign el.scrollTop — no import required.
Three numbers. Content height, visible height, and current scroll offset.
Jump to end. Setting scrollTop to scrollHeight clamps near the bottom.
Threshold. MDN recommends ≤ 1 because of rounding / subpixels.
Use case. Unlock “I agree” or load more when the user finishes reading.
Compatibility
Browser Support
Element.scrollTop is Baseline Widely available (MDN: since July 2015). Safe across modern and older evergreen browsers.
✓ Baseline · Widely available
Element.scrollTop
Get or set vertical scroll offset in CSS pixels — long-standing CSSOM View support.
99%Widely available
Google ChromeAll versions · Desktop & Mobile
Full support
Mozilla FirefoxAll versions · Desktop & Mobile
Full support
Apple SafariAll versions · macOS & iOS
Full support
Microsoft EdgeAll versions · Chromium & Legacy
Full support
Internet ExplorerIE 6+ · Legacy environments
Full support
OperaAll modern versions
Full support
scrollTopExcellent
Bottom line: Safe for production. Remember subpixel values, possible negatives, and Safari overscroll when writing edge checks.
Frequently Asked Questions
It gets or sets how many pixels the element's content is scrolled vertically from its top edge. A positive value means the content has been scrolled down.
No. MDN marks Element.scrollTop as Baseline Widely available (since July 2015). It is not Deprecated, Experimental, or Non-standard.
Yes. Modern browsers can return subpixel-precise floating-point values, so scrollTop is not always a whole number.
It is usually 0 when the element has not been scrolled vertically. If the document is not the active document, the returned value is 0.
Yes, in some layouts (for example column-reverse) or during Safari overscroll. Values can go below 0 in those cases.
Use a threshold because scrollTop can be fractional: Math.abs(element.scrollHeight - element.clientHeight - element.scrollTop) <= 1.