.scrollTop() gets or sets the vertical scroll offset in pixels — how much content is hidden above the visible area (since jQuery 1.2.6). At the top (or if not scrollable), the value is 0.
Remember
$el.scrollTop() // getter → Number (first element)
$el.scrollTop(300) // setter → jQuery (all matched)
$(window).scrollTop() // page vertical scroll
$(window).scrollTop(0) // jump to top of page
Select a scrollable element (or the window), then get or set the offset.
Pick a scrollable container (overflow: auto/scroll) or $(window).
Call .scrollTop() with no args to read the current offset.
Call .scrollTop(value) to jump to a vertical position.
Optionally animate with .animate({ scrollTop: value }).
Piece
Required?
Role
jQuery selection
Yes
Element(s) or window / document
value
Setter only
New vertical position in pixels
Return
—
Getter → Number; setter → jQuery (chainable)
Pseudocode
Pseudocode
function scrollTop(selection, value):
if value is missing:
return firstElement.verticalScrollPixels // or 0
for each el in selection:
el.verticalScrollPixels = value
return selection
.scrollTop() has shipped since jQuery 1.2.6 and works in all modern browsers with jQuery loaded. It maps to the native scroll offset APIs under the hood.
✓ jQuery 1.2.6+
.scrollTop()
Supported everywhere jQuery runs in the browser. Use it on scrollable elements or $(window) for page scroll.
100%Browser support
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
.scrollTop()Excellent
Bottom line: Call .scrollTop() to read and .scrollTop(n) to set. Prefer .animate({ scrollTop: n }) for smooth motion.
Analysis
Performance Notes
Approach
Cost
Best for
.scrollTop() / .scrollTop(n)
Cheap
Instant jumps, one-off reads
.animate({ scrollTop })
Frames
Smooth UX / back-to-top
Scroll event spam
High
Throttle or debounce listeners
Reading or setting scroll is inexpensive. Cost spikes when you attach heavy work to every scroll event — throttle those handlers.
Remember
Key Takeaways
Role: get/set vertical pixels hidden above the view.
One line:.scrollTop() reads vertical offset; .scrollTop(n) sets it — use $(window) for the page.
Frequently Asked Questions
With no arguments, .scrollTop() returns the vertical scroll offset of the first matched element as a number of pixels hidden above the visible area. With a number, .scrollTop(value) sets that offset for every matched element and returns the jQuery object for chaining.
.scrollTop() is vertical (pixels hidden above). .scrollLeft() is horizontal (pixels hidden to the left). Both have been available since jQuery 1.2.6 and share the same getter/setter pattern.
Yes. $(window).scrollTop() reads how far the page has scrolled down, and $(window).scrollTop(0) jumps to the top. That is the usual pattern for sticky headers and back-to-top buttons.
Either the element is already at the top, or it is not vertically scrollable (content fits, or overflow is not set). On $(window), 0 means the page is at the very top.
Yes. Use $el.animate({ scrollTop: target }, duration) for a smooth scroll. For an instant jump, call .scrollTop(value) directly. Call .stop() first if users click repeatedly.
No. Elements with display:none have no reliable scroll layout. Show the element first, then read or set .scrollTop().