HTML DOM Element scrollWidth
Examples
Get the height and width of an element, including padding:
let x = element.scrollHeight;
let y = element.scrollWidth;
How padding, border, and scrollbar affects the scrollWidth and scrollHeight:
let x = element.scrollHeight;
let y = element.scrollWidth;
More examples below.
Description
The scrollWidth
property returns the width of an element,
including padding, excluding borders, scrollbars or margins.
The scrollWidth
property returns the width in pixels.
The scrollWidth
property is read-only.
Note
Both scrollWidth
and scrollHeight
return the entire height and width of an element, including what is not viewable (because of overflow).
See Also:
Syntax
Return Value
More Examples
Set the height and width of an element to the values returned from scrollHeight and scrollWidth:
element.style.width = element.scrollWidth + "px";
Browser Support
element.scrollWidth
is supported in all browsers:
Chrome | Edge | Firefox | Safari | Opera | IE |
Yes | Yes | Yes | Yes | Yes | Yes |