Home

documentdocumentElementscrollTop

document.documentElement.scrollTop is a property of the root HTML element that reports the vertical scroll offset of the document. It returns the number of pixels that the document’s content is scrolled from the top of the page. The root element is typically the html element, and in standards-compliant mode this element is considered the scrolling container for the document.

Cross-browser considerations: in older browsers or in quirks mode, the scrolling element can be document.body instead

Usage and behavior: reading document.documentElement.scrollTop yields the current vertical scroll offset. You can also assign a

Limitations: the usefulness of document.documentElement.scrollTop depends on the browser’s rendering mode and the presence of scrollable

See also: window.pageYOffset, document.body.scrollTop, window.scrollTo.

of
document.documentElement.
This
historical
difference
means
that
reading
or
writing
scroll
positions
may
require
checks
against
both
properties
to
be
cross-browser
compatible.
A
common
approach
is
to
use
a
fallback
pattern
such
as
window.pageYOffset
or
combine
document.documentElement.scrollTop
and
document.body.scrollTop.
value
to
this
property
to
attempt
to
scroll
to
a
new
position
in
browsers
where
the
root
element
is
the
scrolling
container.
However,
in
many
modern
scenarios
it
is
more
reliable
to
use
window.scrollTo
or
similar
methods,
as
they
handle
scrolling
across
different
elements
and
browser
quirks.
content.
If
the
document
area
is
not
scrollable,
the
property
typically
returns
zero.
In
dynamic
layouts
or
when
dealing
with
frames
or
iframes,
scrolling
context
may
differ.