.innerWidth() gets or sets the width of matched elements including padding, but not border or margin (getter since 1.2.6; setter since 1.8). The getter returns a unitless pixel Number.
Remember
$("div").innerWidth() // Number → content + padding
$("div").innerWidth(100) // set inner width to 100px
$("div").innerWidth(fn) // per-element setter (1.8+)
.width() → content only
.innerWidth() → content + padding
.outerWidth() → content + padding + border
Measure or set the padded inner box — never on window or document.
Select a DOM element (not window or document).
Call .innerWidth() with no args to read content + padding as a Number.
Pass a Number or CSS string to set that inner width on every match.
Use the callback form when each element needs a different value (jQuery 1.8+).
Piece
Required?
Role
jQuery selection
Yes
Element(s) only — not window/document
value / function
Setter only (1.8+)
New inner width (Number, string, or per-element fn)
Return
—
Getter → Number (or undefined if empty); setter → jQuery
Pseudocode
Pseudocode
function innerWidth(selection, value):
if selection is empty:
return undefined
if value is missing:
el = first matched element
return contentWidth(el) + horizontalPadding(el)
for each el in selection:
if value is a function:
newW = value(index, currentInnerWidth)
else:
newW = value
set CSS width so content + padding = newW
return selection
Reference
Cheat Sheet
Keep these facts handy while measuring the padded box.
Measure while the element is visible. Temporary show/re-hide tricks are slow and may go away.
empty
Empty set → undefined
No first element means no Number. Guard selections before doing math.
fraction
Values may be fractional
Sub-pixel layouts can return numbers like 136.5. Round only when your UI needs integers.
Compatibility
Browser Support
.innerWidth() getter has shipped since jQuery 1.2.6; the setter and callback forms arrived in jQuery 1.8. Works in all modern browsers with jQuery loaded.
✓ jQuery 1.2.6+
.innerWidth()
Dimension API for content width plus padding — getter returns a unitless Number; setter accepts Number, string, or function (1.8+).
100%Browser support
Google ChromeAll versions · Desktop & Mobile
Full support
Mozilla FirefoxAll versions · Desktop & Mobile
Full support
Apple SafariAll versions · macOS & iOS
Full support
Microsoft EdgeAll versions · Chromium & Legacy
Full support
Internet ExplorerIE 6+ · Legacy environments
Full support
OperaAll modern versions
Full support
.innerWidth()Excellent
Bottom line: Use .innerWidth() when padding must count. Switch to .width() for content only, or .outerWidth() when border (or margin) matters.
Analysis
Performance Notes
Approach
Cost
Best for
.innerWidth()
Layout read
Padded-box math
.width()
Layout read
Content-only math
Repeated reads in a loop
Can thrash layout
Cache the Number first
Dimension getters force layout. Read once, reuse the Number, and avoid calling .innerWidth() inside tight loops unless needed.
Remember
Key Takeaways
Role: get/set width including padding as a unitless Number.
Box ladder:width → innerWidth → outerWidth.
Scope: elements only — use .width() for window/document.
One line:.innerWidth() is content + padding — get for padded-box math, set since 1.8, and leave window/document to .width().
Frequently Asked Questions
.innerWidth() with no arguments returns the width of the first matched element including padding (not border or margin) as a unitless pixel Number. .innerWidth(value) or .innerWidth(function) sets that inner width on every matched element and returns the jQuery object for chaining.
.width() is content only. .innerWidth() adds horizontal padding. .outerWidth() adds padding and border (pass true to include margin). All getters return unitless Numbers.
No. The API is for elements only. Use $(window).width() for the viewport and $(document).width() for the full page.
The getter has been available since jQuery 1.2.6. The setter .innerWidth(value) and the callback form arrived in jQuery 1.8.
Calling .innerWidth() on an empty jQuery set returns undefined (null before jQuery 3.0). Always check that your selection matched something before using the Number.
No. Values can be wrong (often 0) when the element or a parent is hidden. Measure while visible. Fractional pixels are possible — do not assume an integer.