HTML DOM scrollWidth property
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 scrollWidth property is a read-only property that returns the pixel width of the element, including padding but not margin or border; it is an integer measured in pixels (px).

The scrollWidth value equals the minimum width the element needs to fit all content in the viewport without using a horizontal scrollbar. The width is measured the same way as clientWidth: it includes the element's padding but not its border, margin or vertical scrollbar (if present). It may also include the width of pseudo-elements such as ::before or ::after. If the element's content fits without needing a horizontal scrollbar, its scrollWidth equals clientWidth
This is a read-only property.

Browser support
| property | |||||
|---|---|---|---|---|---|
| scrollWidth | Yes | Yes | Yes | Yes | Yes |
Syntax
element.scrollWidth
Technical Details
| Return Value: | Returns an integer representing the pixel width 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