HTML DOM clientWidth property
Example
Get the width of the div element, including padding:
var
elmnt
=
document
.
getElementById
(
"
myDIV
"
)
;
var
txt
=
"
The height of the div element, including padding:
"
elmnt
.
clientHeight
"
px
"
;
txt
+=
"
The width of the div element, including padding:
"
elmnt
.
clientWidth
"
px
"
;
Try it »
Definition and Usage
The clientWidth property is a read-only property that returns the pixel width of the element, including padding but not the border, margin or scrollbar; it is an integer measured in pixels (px).
The clientWidth property of inline elements and elements without CSS styling is 0.

Note: To understand this property, you can refer to CSS Box Model.
Tip: This property is usually used together with the clientHeight property.
Tip: Use offsetHeight and offsettWidth The property returns the visible height and width of the element, including padding and border.
Tip: To add a scrollbar to an element, you can use overflow attribute.
This is a read-only property.

Browser support
| property | |||||
|---|---|---|---|---|---|
| clientWidth | Yes | Yes | Yes | Yes | Yes |
Syntax
element.clientWidth
Technical Details
| Return Value: | Returns an integer representing the pixel width of the element. |
|---|
More examples
Example
The following example demonstrates the difference between the clientHeight/clientWidth and offsetHeight/offsetWidth properties:
var
elmnt
=
document
.
getElementById
(
"
myDIV
"
)
;
var
txt
=
"
"
;
txt
+=
"
The height includes padding:
"
elmnt
.
clientHeight
"
px
"
;
txt
+=
"
The height includes padding and border:
"
elmnt
.
offsetHeight
"
px
"
;
txt
+=
"
The width includes padding:
"
elmnt
.
clientWidth
"
px
"
;
txt
+=
"
The width includes padding and border:
"
elmnt
.
offsetWidth
"
px
"
;
Try it »
Example
The following example demonstrates the difference between the clientHeight/clientWidth and offsetHeight/offsetWidth properties after a scrollbar is added to the element:
var
elmnt
=
document
.
getElementById
(
"
myDIV
"
)
;
var
txt
=
"
"
;
txt
+=
"
The style information of the div:
"
;
txt
+=
"
The height includes padding:
"
elmnt
.
clientHeight
"
px
"
;
txt
+=
"
The height includes padding, border and scrollbar:
"
elmnt
.
offsetHeight
"
px
"
;
txt
+=
"
The width includes padding:
"
elmnt
.
clientWidth
"
px
"
;
txt
+=
"
The width includes padding, border and scrollbar:
"
elmnt
.
offsetWidth
"
px
"
;
Try it »
Element object