You’re reading the English version of this content since no translation exists yet for this locale. Help us translate this article!
Element.scrollTop property gets or sets the number of pixels that an element's content is scrolled vertically.
scrollTop value is a measurement of the distance from the element's top to its topmost visible content. When an element's content does not generate a vertical scrollbar, then its
scrollTop value is
On systems using display scaling,
scrollTop may give you a decimal value.
// Get the number of pixels scrolled. var intElemScrollTop = someElement.scrollTop;
After running this code,
intElemScrollTop is an integer corresponding to the number of pixels that the
element's content has been scrolled upwards.
// Set the number of pixels scrolled. element.scrollTop = intValue;
scrollTop can be set to any integer value, with certain caveats:
- If the element can't be scrolled (e.g. it has no overflow or if the element has a property of "non-scrollable"),
scrollTopdoesn't respond to negative values; instead, it sets itself back to
- If set to a value greater than the maximum available for the element, scrollTop settles itself to the maximum value.
|CSS Object Model (CSSOM) View Module
The definition of 'scrollTop' in that specification.
|Chrome Full support 43||Edge Full support 12||Firefox Full support Yes||IE Full support Yes||Opera Full support Yes||Safari Full support 6||WebView Android Full support Yes||Chrome Android Full support 43||Firefox Android Full support Yes||Opera Android Full support Yes||Safari iOS Full support Yes||Samsung Internet Android Full support Yes|
- Full support
- Full support