Home

documentdocumentElementoffsetHeight

document.documentElement.offsetHeight is a property that returns the height, in CSS pixels, of the root HTML element (the <html> element) as it is laid out by the browser. It includes the element’s vertical padding and borders, and is read from the DOM as a numeric value. The property is read-only and reflects the element’s rendered size at a given moment.

In practice, document.documentElement refers to the root of the document, and offsetHeight is one way to measure

Common use cases include simple layout calculations, responsive adjustments, and scroll-related logic where a stable metric

Usage example: var h = document.documentElement.offsetHeight;

Limitations include potential reflows when the page layout changes, and the fact that offsetHeight is only

its
height.
However,
this
value
does
not
reliably
represent
the
total
height
of
the
page
content
nor
the
viewport
height
in
all
situations.
For
browser
computations,
other
properties
are
often
more
appropriate:
window.innerHeight
or
document.documentElement.clientHeight
give
viewport
height;
document.documentElement.scrollHeight
(or
document.body.scrollHeight
in
some
layouts)
yields
the
full
document
height.
of
the
root
element’s
rendered
height
is
helpful.
Developers
should
be
aware
of
cross-browser
differences
and
modes:
in
standards
vs.
quirks
mode,
and
with
zoom
levels,
measurements
may
vary
slightly.
Therefore,
when
precise
page
height
information
is
required,
it
is
advisable
to
consider
multiple
metrics
or
feature-detect
browser
behavior
and
avoid
relying
on
offsetHeight
alone.
one
of
several
related
measurements.
For
robust
sizing
strategies,
combine
offsetHeight
with
scrollHeight
and
clientHeight
as
appropriate,
and
test
across
target
browsers.