HTML DOM Element clientWidth Property
- Previous page clientTop
- Next page cloneNode()
- Go back to the previous level HTML DOM Elements Object
Definition and Usage
clientWidth
Property returns the visible width of the element, including padding, but not including borders, scrollbars, or margins, in pixels.
clientWidth
The property is read-only.
See also:CSS Box Model Tutorial
See also:
To add a scrollbar to an element, please use CSS Overflow Property.
Example
Example 1
Get the height and width of "myDIV", including padding:
const element = document.getElementById("myDIV"); let text = "clientHeight: " + element.clientHeight + "px<br>"; text += "clientWidth: " + element.clientWidth + "px";
Example 2
Example 2: Difference between clientHeight/clientWidth and offsetHeight/offsetWidth
Without scrollbars:
const element = document.getElementById("myDIV"); let text = ""; text += "clientHeight: " + element.clientHeight + "px<br>"; text += "offsetHeight: " + element.offsetHeight + "px<br>"; text += "clientWidth: " + element.clientWidth + "px<br>"; text += "offsetWidth: " + element.offsetWidth + "px";
With scrollbars:
const element = document.getElementById("myDIV"); let text = ""; text += "clientHeight: " + element.clientHeight + "px<br>"; text += "offsetHeight: " + element.offsetHeight + "px<br>"; text += "clientWidth: " + element.clientWidth + "px<br>"; text += "offsetWidth: " + element.offsetWidth + "px";
Syntax
element.clientWidth
Return value
Type | Description |
---|---|
Value | The visible width of the element (in pixels), including padding. |
Browser support
All browsers support element.clientWidth
:
Chrome | IE | Edge | Firefox | Safari | Opera |
---|---|---|---|---|---|
Chrome | IE | Edge | Firefox | Safari | Opera |
Supported | Supported | Supported | Supported | Supported | Supported |
- Previous page clientTop
- Next page cloneNode()
- Go back to the previous level HTML DOM Elements Object