.outerWidth() gets or sets the width of matched elements including padding and border (getter since 1.2.6; setter since 1.8). Pass true to include margin. The getter returns a unitless pixel Number.
Remember
$("div").outerWidth() // content + padding + border
$("div").outerWidth(true) // also include margin
$("div").outerWidth(100) // set outer width (1.8+)
$("div").outerWidth(100, true) // set accounting for margin
.width() → content only
.innerWidth() → content + padding
.outerWidth() → content + padding + border
.outerWidth(true)→ + margin
Measure or set the border box — never on window or document.
Select a DOM element (not window or document).
Call .outerWidth() to read content + padding + border.
Pass true when horizontal margin must count too.
Pass a Number/string (or callback) to set outer width since jQuery 1.8.
Piece
Required?
Role
jQuery selection
Yes
Element(s) only — not window/document
includeMargin
Optional
true adds horizontal margin
value / function
Setter only (1.8+)
New outer width (Number, string, or per-element fn)
Pseudocode
Pseudocode
function outerWidth(selection, valueOrMargin, includeMargin):
if selection is empty:
return undefined
if valueOrMargin is missing or is a Boolean:
el = first matched element
w = contentWidth + padding + border
if valueOrMargin === true: w += margin
return w
for each el in selection:
newW = valueOrMargin is function
? valueOrMargin(index, currentOuterWidth)
: valueOrMargin
set CSS width so outer box = newW
return selection
Reference
Cheat Sheet
Keep these facts handy while measuring the border box.
Measure while the element is visible. Temporary show/re-hide tricks are slow and may go away.
table
border-collapse: collapse can surprise
Shared borders on collapsed tables may make per-cell .outerWidth() look wrong. Prefer measuring the table as a whole.
fraction
Values may be fractional
Sub-pixel layouts can return numbers like 140.5. Round only when your UI needs integers.
Compatibility
Browser Support
.outerWidth() 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+
.outerWidth()
Dimension API for content + padding + border — pass true for margin. 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
.outerWidth()Excellent
Bottom line: Use .outerWidth() for the border box. Pass true for margin. Switch to .width() / .innerWidth() for smaller box edges.
Analysis
Performance Notes
Approach
Cost
Best for
.outerWidth()
Layout read
Border-box math
.outerWidth(true)
Layout read
Space including margin
Repeated reads in a loop
Can thrash layout
Cache the Number first
Dimension getters force layout. Read once, reuse the Number, and avoid calling .outerWidth() inside tight loops unless needed.
Remember
Key Takeaways
Role: get/set width including padding and border.
Margin: pass true when spacing must count.
Box ladder:width → innerWidth → outerWidth.
Scope: elements only — use .width() for window/document.
One line:.outerWidth() is the border box — pass true for margin, set since 1.8, and leave window/document to .width().
Frequently Asked Questions
.outerWidth() with no arguments returns the width of the first matched element including padding and border as a unitless pixel Number. Pass true to include margin. .outerWidth(value) or .outerWidth(function) sets that outer width on every matched element (since 1.8).
.width() is content only. .innerWidth() adds horizontal padding. .outerWidth() adds padding and border. .outerWidth(true) also includes 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 .outerWidth(value) and the callback form arrived in jQuery 1.8.
Calling .outerWidth() 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.