Get the entire height and width of an element, including padding:
More "Try it Yourself" examples below.
The scrollWidth property returns the entire width of an element in pixels, including padding, but not the border, scrollbar og margin.
Tip: Use the scrollHeight property to return the entire height of an element.
The scrollWidth and scrollHeight properties return the entire height and width of an element, including the height and width that is not viewable (because of overflow).
Tip: To add scrollbars to an element, use the CSS overflow property.
This property is read-only.
Property | |||||
---|---|---|---|---|---|
scrollWidth | Yes | Yes | Yes | Yes | Yes |
Return Value: | A Number, representing the entire width (horizontally) of an element, in pixels |
---|
Using padding, border, scrollbar and margin to show how this affects the scrollWidth and scrollHeight property:
Return the scrollHeight and scrollWidth of an element and then set its height and width to the values returned from scrollHeight and scrollWidth: