Element.clientWidth is a read-only instance property that returns an element’s inner width in pixels. Learn what padding and scrollbars do to the value, how the root element reports viewport width, and how it compares to offsetWidth / scrollWidth—with five examples and try-it labs.
01
Kind
Instance property
02
Access
Read-only
03
Type
Integer (px)
04
Includes
Padding
05
Excludes
Border · margin
06
Status
Baseline widely
Fundamentals
Introduction
Layout work often needs the visible content box width: how wide is the area inside the borders? That is what clientWidth answers.
It includes padding, but leaves out borders, margins, and any vertical scrollbar. For elements with no CSS/inline layout box, the value is 0.
JavaScript
const box = document.getElementById("box");
console.log(box.clientWidth); // inner width in pixels
💡
Beginner tip
Think: client = the client area (content + padding). Borders sit outside that area and do not count.
Concept
Understanding the Property
MDN: the clientWidth read-only property of the Element interface is zero for elements with no CSS or inline layout boxes; otherwise, it is the inner width of an element in pixels. It includes padding but excludes borders, margins, and vertical scrollbars (if present).
Read-only — change CSS/layout, then read again.
Integer pixels — rounded layout measurement.
Formula — CSS width + padding − vertical scrollbar width.
Baseline — widely available since July 2015 (MDN).
Foundation
📝 Syntax
JavaScript
clientWidth
Value
An integer: the element’s inner width in pixels.
Item
Detail
Type
number (integer pixels)
Access
Read-only
Includes
Content width + padding
Excludes
Border, margin, vertical scrollbar
⚠️
Root / viewport
On document.documentElement (the <html> root), or on <body> in quirks mode, clientWidth returns the viewport width excluding any scrollbar.
Pattern
📋 Measuring a Box
Give an element a fixed width and padding, then read clientWidth:
Element.clientWidth is Baseline Widely available (MDN: across browsers since July 2015). Logos use the shared browser-image-sprite.png sprite from this project.
Bottom line: Use clientWidth for the visible client area. Compare with offsetWidth (borders) and scrollWidth (overflow). On the root element it reports viewport width.
Wrap Up
Conclusion
clientWidth is the go-to measurement for an element’s inner width. Include padding, skip borders and margins, and use the root element when you need viewport width.
Use document.documentElement.clientWidth for viewport
Re-read after layout or resize changes
Pair with clientHeight for 2D measurements
❌ Don’t
Expect borders or margins to be included
Assign to clientWidth (read-only)
Confuse it with CSS width alone when padding exists
Assume non-layout elements return a useful size
Skip reflow timing when measuring right after DOM inserts
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about clientWidth
Read-only inner width in pixels—padding in, border and margin out.
5
Core concepts
📄01
Get only
on Element
Kind
📝02
Integer px
inner width
Type
🔍03
Layout math
panels & overflow
Use
✅04
Baseline
widely available
Status
🎯05
Padding in
border out
Tip
❓ Frequently Asked Questions
It returns the element's inner width in pixels, including padding but excluding borders, margins, and vertical scrollbars.
No. MDN marks Element.clientWidth as Baseline Widely available (since July 2015). It is not Deprecated, Experimental, or Non-standard.
No. It is a read-only instance property. Change layout with CSS or style APIs, then read clientWidth again.
Roughly CSS width + CSS padding − width of a vertical scrollbar if one is present.
On the root <html> element (or <body> in quirks mode), clientWidth returns the viewport width excluding any scrollbar.
offsetWidth includes borders (and often scrollbars). scrollWidth is the full scrollable content width, which can be larger than the visible client area.
Did you know?
A classic overflow check is el.scrollWidth > el.clientWidth—true when content is wider than the visible client area.