jQuery .outerWidth() Method

Beginner
⏱️ 10 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
Border box width

What You’ll Learn

The .outerWidth() method gets or sets the width of matched elements including padding and border as a unitless pixel Number — ideal when the full border box matters for layout math and horizontal row totals. This tutorial covers the optional includeMargin flag, getter and setter overloads, comparisons with .width(), .innerWidth(), and .outerHeight(), callback setters since 1.8, and practical row-sum patterns.

01

Getter

.outerWidth() → Number

02

+ Margin

true flag

03

Setter

Since 1.8

04

+ Border

Not margin*

05

Callback

Since 1.8

06

Since 1.2.6

Getter API

Introduction

After learning .innerWidth(), which measures content plus padding, you often need a dimension that also includes border — especially for fixed sidebars, horizontal card rows with margins, and subtracting one element’s full footprint from the viewport. jQuery’s .outerWidth() returns a plain number for the border box, ready for math and .animate() without parsing "96px" strings.

Available since jQuery 1.2.6 as a getter, .outerWidth() gained setter and callback forms in jQuery 1.8. Pass true as .outerWidth(true) to include horizontal margin in the measurement. Unlike .width(), it does not work on $(window) or $(document) — use it on DOM elements only.

Understanding the .outerWidth() Method

Given a jQuery object, .outerWidth() either returns the current width of the first matched element — content plus horizontal padding plus border — as a unitless pixel Number (getter), or sets the CSS width on every matched element so the outer box equals your value (setter). Margin is excluded by default; pass true to include it.

Think of .outerWidth() as a ruler that extends through padding and border. .width() stops at the content edge; .innerWidth() adds padding only; .outerWidth(true) continues through margin. Use .outerWidth() when subtracting a sidebar from the viewport or summing horizontal card rows — for example, available = $(window).width() - $("#sidebar").outerWidth().

💡
Beginner Tip

On a box with padding: 12px, border: 4px solid, and content width 24px: .width() returns 24, .innerWidth() returns 48, .outerWidth() returns 56. Add .outerWidth(true) to include horizontal margin as well.

📝 Syntax

jQuery .outerWidth() has four argument forms — one getter and three setters:

Get — optional includeMargin (since 1.2.6)

jQuery
.outerWidth( [ includeMargin ] )  // -> Number
  • includeMargin — optional Boolean. When true, horizontal margin is included in the returned width.
  • Returns the width of the first matched element including padding and border as a unitless pixel Number.
  • Margin excluded by default — pass true to add it.
  • Not for $(window) or $(document) — elements only.
  • Returns undefined when the jQuery set is empty.

Set — Number with optional includeMargin (since 1.8)

jQuery
.outerWidth( value [, includeMargin ] )  // -> jQuery
  • value — target outer width in pixels as a Number (e.g. 60).
  • includeMargin — optional Boolean; when true, margin is factored into the CSS width calculation.
  • jQuery adjusts the CSS width so content plus padding plus border (and optionally margin) equals the value.
  • Returns the original jQuery object for chaining — e.g. .outerWidth(60).addClass("mod").

Set — callback function (since 1.8)

jQuery
.outerWidth( function( index, width ) {
  // return new outer width (Number)
} )
  • index — zero-based position of the element in the matched set.
  • width — current outer width of this element before the change.
  • Return a new outer width per element; jQuery applies it and returns the jQuery object.

Return value

  • Getter — unitless Number (pixels). May be fractional on sub-pixel layouts. Empty set → undefined.
  • Setter — the original jQuery object for chaining.

Important note

⚠️
Hidden elements

.outerWidth() on display:none or hidden elements is unreliable — jQuery may return 0. Measure after showing the element, clone it off-screen, or use a visibility trick before reading.

Official jQuery API example

jQuery
var p = $( "p" ).first();
$( "#result" ).text(
  "outerWidth: " + p.outerWidth() +
  " , outerWidth(true): " + p.outerWidth( true )
);

⚡ Quick Reference

GoalCode
Read border-box width (Number)$("div").outerWidth()
Include horizontal margin$("div").outerWidth(true)
Set outer width in pixels$("div").outerWidth(60)
Shrink outer width per click$("div").outerWidth(function(i, w){ return w - 12; })
Content width only (no padding)$("div").width()
Padding only (no border)$("div").innerWidth()
Sum horizontal card row with margin$(".card").get().reduce(function(s, el){ return s + $(el).outerWidth(true); }, 0)
Viewport minus fixed sidebar$(window).width() - $("#sidebar").outerWidth()

📋 .outerWidth() vs .innerWidth() vs .width() vs .outerHeight()

Four dimension helpers — content box, padded inner box, full border box, and the vertical counterpart.

.outerWidth()
+ border

Get/set width including padding and border — pass true to add margin

.innerWidth()
+ pad

Content plus padding — border and margin excluded

.width()
content

Content width only — works on window and document

.outerHeight()
vert

Vertical counterpart — height including padding, border, optional margin

Examples Gallery

Examples 1–2 follow the official jQuery API documentation. Examples 3–5 compare dimension methods, demonstrate callback setters, and sum horizontal card row widths with margin. Use DevTools or the Try-it links to run each snippet.

📚 Getting Started

Official jQuery demos for reading and setting outer width.

Example 1 — Official Demo: Get First Paragraph Outer Width

Read the border-box outer width of the first <p>, with and without margin.

jQuery
var p = $( "p" ).first();
$( "#result" ).text(
  "outerWidth: " + p.outerWidth() +
  " , outerWidth(true): " + p.outerWidth( true )
);
Try It Yourself

How It Works

No-argument .outerWidth() returns a unitless pixel Number for the first element — content width plus horizontal padding plus border. Pass true as .outerWidth(true) to add horizontal margin to the total.

Example 2 — Official Demo: Set Outer Width on Click

Click each red box once — its outer width is set to modWidth, then modWidth decreases by 8 for the next box.

jQuery
var modWidth = 60;
$( "div" ).one( "click", function() {
  $( this ).outerWidth( modWidth ).addClass( "mod" );
  modWidth -= 8;
});
Try It Yourself

How It Works

.outerWidth(60) sets the CSS width so the outer box (content plus padding plus border) totals 60 pixels. The setter returns the jQuery object, so .addClass("mod") chains immediately. Setter support arrived in jQuery 1.8.

📈 Practical Patterns

Compare dimension APIs, callback setters, and horizontal row layout math.

Example 3 — Compare .width(), .innerWidth(), and .outerWidth()

See how padding, border, and margin affect each dimension method on the same box.

jQuery
var $box = $( "#box" );
var lines = [
  ".width()              → " + $box.width() + "px (content)",
  ".innerWidth()         → " + $box.innerWidth() + "px (+ padding)",
  ".outerWidth()         → " + $box.outerWidth() + "px (+ border)",
  ".outerWidth(true)     → " + $box.outerWidth( true ) + "px (+ margin)"
];
$( "#out" ).html( lines.join( "<br>" ) );
Try It Yourself

How It Works

All four return unitless Numbers. .width() stops at content; .innerWidth() adds padding; .outerWidth() adds border; .outerWidth(true) adds margin. Pick the method that matches what you are measuring — layout subtraction often uses .outerWidth() on fixed sidebars.

Example 4 — Callback Setter: Shrink Outer Width by 12px

Each click reduces the panel’s outer width by 12 pixels, with a minimum of 48px.

jQuery
function showVal() {
  $( "#val" ).text( $( "#panel" ).outerWidth() + "px" );
}
showVal();
$( "#panel" ).on( "click", function() {
  $( this ).outerWidth( function( index, width ) {
    return Math.max( 48, width - 12 );
  });
  showVal();
});
Try It Yourself

How It Works

Since jQuery 1.8, the callback setter receives index and the current outer width. Return a new value — here width - 12 with a floor — without manually reading and writing in separate steps.

Example 5 — Sum Card Row: Total Horizontal Space with .outerWidth(true)

Loop through a horizontal row of cards and sum each element’s outer width including margin — useful for row layout and scroll-area planning.

jQuery
var sum = 0;
$( ".card" ).each( function() {
  sum += $( this ).outerWidth( true );
});
$( "#total" ).text(
  "Total horizontal space (outerWidth with margin): " + sum + "px"
);
Try It Yourself

How It Works

.outerWidth(true) includes margin — essential when summing horizontal row elements where gaps between cards matter. Without true, margins would be double-counted or missed depending on collapse behavior. This pattern is common for carousel width estimates and horizontal scroll placeholders.

🚀 Common Use Cases

  • Viewport minus sidebaravailable = $(window).width() - $("#sidebar").outerWidth() to size content beside a fixed sidebar.
  • Horizontal row totals — sum .outerWidth(true) across cards to estimate total row width including margins.
  • Equal column outer widths — read each column’s .outerWidth(), find the max, set all to match bordered columns.
  • Shrink-on-click UI — callback setter .outerWidth(function(i, w){ return w - 12; }) for interactive panels.
  • Dimension debugging — compare .width(), .innerWidth(), and .outerWidth() to trace box-model mismatches.
  • Animation targets — pair measured .outerWidth() with .animate() when border must stay inside the animated box.

🧠 How .outerWidth() Reads and Writes Dimensions

1

Match elements

jQuery object holds DOM elements — not window or document.

Input
2

Detect mode

No args or true → getter. Number, function, or value + true → setter (1.8+).

Route
3

Measure or apply

Getter reads offsetWidth (content + padding + border). Optional true adds margin. Setter adjusts CSS width to hit the target outer box.

DOM
4

Return result

Getter → unitless pixel Number (or undefined if empty). Setter → same jQuery object for chaining.

📝 Notes

  • Getter available since jQuery 1.2.6 — setter and callback since 1.8.
  • Getter returns a unitless pixel Number from the first matched element only.
  • Includes horizontal padding and border — margin excluded unless true is passed.
  • Not for $(window) or $(document) — use .width() on those instead.
  • Empty jQuery set → getter returns undefined.
  • Unreliable on hidden (display:none) elements — may return 0.
  • On border-collapse: collapse tables, per-cell .outerWidth() may be inaccurate — measure the table or use getBoundingClientRect().
  • Values can be fractional (e.g. 86.5) on sub-pixel or zoomed displays.
  • Setter returns the original jQuery object — e.g. .outerWidth(60).addClass("mod").

Browser Support

.outerWidth() getter has been part of jQuery since 1.2.6+. Setter and callback forms arrived in 1.8+. It wraps cross-browser reads of offsetWidth (content plus padding plus border) with optional margin via the true flag — no browser-specific quirks beyond jQuery itself.

jQuery 1.2.6+

jQuery .outerWidth()

Supported in jQuery 1.x, 2.x, and 3.x across all modern browsers and IE with supported jQuery builds. Native equivalent: element.offsetWidth — jQuery adds collection semantics, unitless Numbers, optional margin, setter support, and callback chaining.

100% With jQuery loaded
Google Chrome All versions · Desktop & Mobile
Full support
Mozilla Firefox All versions · Desktop & Mobile
Full support
Apple Safari All versions · macOS & iOS
Full support
Microsoft Edge All versions · Chromium & Legacy
Full support
Internet Explorer IE 6+ · Legacy environments
Full support
Opera All modern versions
Full support
.outerWidth() Universal

Bottom line: Safe in any jQuery project. Use .outerWidth() when border belongs in the measurement; pass true when margin matters; use .width() for content-only or window/document reads.

Conclusion

The jQuery .outerWidth() method gets or sets element width including padding and border as a unitless pixel Number — the right dimension helper when the full border box matters for sidebars, horizontal card rows, and layout subtraction. Pass true to include horizontal margin; it sits above .innerWidth() (padding only) and below nothing in the box model stack.

Remember the official demo: $( "p" ).first().outerWidth() reads the border box, and .outerWidth(true) adds margin. Use the setter .outerWidth(60) to target the full outer box, the callback form to shrink per click, and .outerWidth(true) when summing horizontal row elements — but never call .outerWidth() on window or document directly.

💡 Best Practices

✅ Do

  • Use .outerWidth() when border width must be included in the measurement
  • Pass true when summing horizontal row elements where margin gaps matter
  • Use $("#sidebar").outerWidth() to subtract fixed sidebars from viewport width
  • Use the callback setter for shrink/grow patterns based on current outer width
  • Reach for .innerWidth() when border should be excluded from the count

❌ Don’t

  • Call .outerWidth() on $(window) or $(document)
  • Trust .outerWidth() on display:none elements — it may return 0
  • Assume .outerWidth() includes margin — pass true explicitly
  • Rely on per-cell .outerWidth() on border-collapse: collapse tables without testing
  • Forget that an empty jQuery set returns undefined from the getter

Key Takeaways

Knowledge Unlocked

Six things to remember about .outerWidth()

Full border box — margin optional.

6
Core concepts
= 02

Setter

1.8+

Write
brd 03

+ Border

Included

Box
T 04

true

+ Margin

Flag
el 05

Elements

Not window

Scope
hide 06

Hidden

Unreliable

Caveat

❓ Frequently Asked Questions

Calling .outerWidth() with no arguments returns the width of the first matched element including padding and border as a unitless Number — margin excluded. Pass true as .outerWidth(true) to include horizontal margin in the measurement as well. The same Boolean applies to setters: .outerWidth(80) sets the outer box without margin; .outerWidth(80, true) accounts for margin when calculating the CSS width. The getter has been available since jQuery 1.2.6.
.width() returns content width only — padding, border, and margin excluded. .innerWidth() adds horizontal padding on top of content. .outerWidth() adds padding and border (full border box). Pass true to .outerWidth(true) to add margin as well. All three return unitless Numbers for getters — pick the method that matches the CSS layer you are measuring. For raw CSS strings such as '80px' or 'auto', use .css('width') instead.
The getter .outerWidth([includeMargin]) has been available since jQuery 1.2.6. The setter .outerWidth(value [, includeMargin]) and the callback form .outerWidth(function(index, width)) were both added in jQuery 1.8. The callback receives the zero-based index and the element's current outer width; return a new Number to set each element independently — useful for shrink-on-click panels and staggered column layouts.
No — .outerWidth() is for elements only. Unlike .width(), which works on $(window) and $(document), .outerWidth() does not support window or document objects. For viewport width use $(window).width(); for full page scroll width use $(document).width(). Use .outerWidth() when you need the full border box of a DOM element — for example, subtracting a fixed sidebar's outer width from the viewport to size a content area beside it.
Yes — on table elements with border-collapse: collapse, border widths may be shared between adjacent cells and jQuery's .outerWidth() can report values that differ from what you expect when measuring individual cells or columns. Prefer measuring the table as a whole, temporarily set border-collapse: separate for measurement, or use getBoundingClientRect() when precise per-cell border math is critical. For typical block-level divs and cards, .outerWidth() behaves predictably.
Calling .outerWidth() on an empty jQuery set returns undefined — there is no first element to measure. On display:none or visibility:hidden elements, .outerWidth() is unreliable and may return 0 because the element is not rendered; temporarily show the element or clone it off-screen before measuring. Returned widths can be fractional (e.g. 86.5) on sub-pixel layouts or zoomed displays; use Math.round() when you need integers for layout or animation targets.
Did you know?

jQuery’s .outerWidth() getter has existed since version 1.2.6 — long before setters arrived in 1.8. It maps closely to the native offsetWidth property: content plus padding plus border, no margin unless you pass true. On a typical element with 4px border and 16px horizontal padding, .outerWidth() reads roughly 24px wider than .innerWidth(). The vertical mirror is .outerHeight() — same box-model rules, different axis. For viewport math, combine $(window).width() with element .outerWidth() on fixed sidebars, but never call .outerWidth() on the window object itself.

Next: .offset()

Learn document coordinates — position elements relative to the page.

.offset() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

6 people found this page helpful