Element.clientWidth is a read-only integer: the element’s inner width in CSS pixels. It includes padding and excludes borders, margins, and vertical scrollbars (MDN).
Read the notes below before you get or set this property. Prefer feature detection when support is limited.
Syntax
Use el.clientWidth. Start with this line.
JavaScript
element.clientWidth
Call
What it does
element.clientWidth
Primary signature.
Built into the browser. Read or assign el.clientWidth — no import required.
Library declarations
JavaScript
element.clientWidth
Parameters
Parameter
Description
Compare property
Optional. offsetWidth / scrollWidth for other questions
Bottom line: Safe for production. Remember root-element reads return viewport width, and inline / no-CSS elements return 0.
Frequently Asked Questions
A read-only integer: the element's inner width in CSS pixels, including padding but excluding borders, margins, and vertical scrollbars (if present).
No. MDN marks Element.clientWidth as Baseline Widely available (since July 2015). It is not Deprecated, Experimental, or Non-standard.
No. It is read-only. Change layout with CSS (or element.style), then read clientWidth again.
Roughly CSS width + CSS padding − width of a vertical scrollbar if one is present. Inline elements and elements with no CSS return 0.
On the root <html> element (or <body> in quirks mode), clientWidth returns the viewport width excluding any scrollbar.
offsetWidth is the border-box width (includes borders, and often scrollbars). scrollWidth is the full scrollable content width, which can be larger than the visible client area.