Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

HTML DOM scrollHeight property

HTML DOM scrollHeight property

Element Object Reference Element object

Example

Get the height and width of the div element, including padding:

var

elmnt

=

document

.

getElementById

(

"

content

"

)

;

var

y

=

elmnt

.

scrollHeight

;

var

x

=

elmnt

.

scrollWidth

;

Try it »


Definition and Usage

The scrollHeight property is a read-only property that returns the pixel height of the element, including padding but not margin or border; it is an integer measured in pixels (px).

The value of scrollHeight equals the minimum height the element needs to fit all the content in the viewport without using a scrollbar. Without a vertical scrollbar, the scrollHeight value is the same as the minimum clientHeight required to fill all content in the element's view. It includes the element's padding but not its border and margin.

scrollHeight also includes pseudo-elements such as ::before and ::after.

This is a read-only property.


Browser support

property
scrollHeight Yes Yes Yes Yes Yes

Syntax

element.scrollHeight 

Technical Details

Return Value: Returns an integer representing the pixel height of the element.

More examples

Example

Use padding, border, scrollbar and margin to demonstrate the changes in the scrollWidth and scrollHeight properties:

var

elmnt

=

document

.

getElementById

(

"

content

"

)

;

var

y

=

elmnt

.

scrollHeight

;

var

x

=

elmnt

.

scrollWidth

;

Try it »

Example

Return the values of the scrollHeight and scrollWidth properties of an element, then use the obtained height and width to set the scrollHeight and scrollWidth property values of another element:

var

elmnt

=

document

.

getElementById

(

"

content

"

)

;

function

getFunction

(

)

{

var

x

=

elmnt

.

scrollWidth

;

var

y

=

elmnt

.

scrollHeight

;

}

function

setFunction

(

)

{

elmnt

.

style

.

height

=

y

.

scrollHeight

"

px

"

;

elmnt

.

style

.

width

=

y

.

scrollWidth

"

px

"

;

}

Try it »


Element Object Reference Element object