jQuery .innerWidth() Method

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

What You’ll Learn

The .innerWidth() method gets or sets the width of matched elements including padding as a unitless pixel Number — ideal when the padded inner box matters for horizontal scroll areas and layout math. This tutorial covers getter and setter overloads, comparisons with .width(), .outerWidth(), and .css("width"), callback setters since 1.8, and practical horizontal scroll-track patterns.

01

Getter

.innerWidth() → Number

02

Setter

Since 1.8

03

+ Padding

Not border

04

vs width

Content only

05

Callback

Since 1.8

06

Since 1.2.6

Getter API

Introduction

After learning .width(), which measures the content box only, you often need a dimension that includes padding — especially for horizontal scroll tracks, tag lists, and comparisons with CSS clientWidth. jQuery’s .innerWidth() returns a plain number for the content area plus horizontal padding, ready for math and .animate() without parsing "144px" strings.

Available since jQuery 1.2.6 as a getter, .innerWidth() gained setter and callback forms in jQuery 1.8. The getter reads the padded inner width of the first matched element; the setter adjusts CSS width so the inner box (content plus padding) matches your target. Unlike .width(), it does not work on $(window) or $(document) — use it on DOM elements only.

Understanding the .innerWidth() Method

Given a jQuery object, .innerWidth() either returns the current width of the first matched element — content plus horizontal padding — as a unitless pixel Number (getter), or sets the CSS width on every matched element so the inner box equals your value (setter). Border and margin are excluded; only padding is added on top of content width.

Think of .innerWidth() as a ruler that extends through left and right padding. .width() stops at the content edge; .outerWidth() continues through border (and optionally margin). Use .innerWidth() when scrollable areas or padded containers need precise pixel targets — for example, fitting a horizontal track to the remaining space beside a fixed label.

💡
Beginner Tip

On a box with padding: 12px and content width 96px: .width() returns 96, .innerWidth() returns 120 (96 + 12 + 12). For the full box including border, use .outerWidth().

📝 Syntax

jQuery .innerWidth() has three argument forms — one getter and two setters:

Get — no arguments (since 1.2.6)

jQuery
.innerWidth()  // -> Number
  • Returns the width of the first matched element including padding as a unitless pixel Number.
  • Border and margin are excluded — horizontal padding is included.
  • Not for $(window) or $(document) — elements only.
  • Returns undefined when the jQuery set is empty.

Set — Number (since 1.8)

jQuery
.innerWidth( value )  // -> jQuery
  • value — target inner width in pixels as a Number (e.g. 120).
  • jQuery adjusts the CSS width so content plus padding equals the value.
  • Returns the original jQuery object for chaining — e.g. .innerWidth(120).addClass("mod").

Set — callback function (since 1.8)

jQuery
.innerWidth( function( index, width ) {
  // return new inner width (Number)
} )
  • index — zero-based position of the element in the matched set.
  • width — current inner width of this element before the change.
  • Return a new inner 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

.innerWidth() 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( "innerWidth: " + p.innerWidth() + "px" );

⚡ Quick Reference

GoalCode
Read padded inner width (Number)$("div").innerWidth()
Set inner width in pixels$("div").innerWidth(120)
Shrink inner width per click$("div").innerWidth(function(i, w){ return w - 15; })
Content width only (no padding)$("div").width()
Include padding + border$("div").outerWidth()
CSS width as string$("div").css("width")
Viewport width (not innerWidth)$(window).width()
Fit scroll track beside label$("#track").innerWidth($("#row").innerWidth() - $("#label").outerWidth(true))

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

Four ways to read horizontal dimensions — content box, padded inner box, full border box, and raw CSS strings.

.innerWidth()
+ pad

Get/set width including padding — returns unitless Number

.width()
content

Content width only — padding and border excluded; works on window/document

.outerWidth()
+ border

Includes padding and border; pass true to add margin

.css()
"120px"

General CSS getter/setter — width returns String with units or auto

Examples Gallery

Examples 1–2 follow the official jQuery API documentation. Examples 3–5 compare dimension methods, demonstrate callback setters, and build a horizontal scroll track. Use DevTools or the Try-it links to run each snippet.

📚 Getting Started

Official jQuery demos for reading and setting inner width.

Example 1 — Official Demo: Get First Paragraph Inner Width

Read the padded inner width of the first <p> and display it.

jQuery
var p = $( "p" ).first();
$( "#result" ).text( "innerWidth: " + p.innerWidth() + "px" );
Try It Yourself

How It Works

No-argument .innerWidth() returns a unitless pixel Number for the first element — content width plus horizontal padding. Border width is not included; that is what .outerWidth() adds.

Example 2 — Official Demo: Set Inner Width on Click

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

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

How It Works

.innerWidth(60) sets the CSS width so the inner box (content plus padding) 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 scroll tracks.

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

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

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

How It Works

All three return unitless Numbers. .width() stops at content; .innerWidth() adds padding; .outerWidth() adds border. Pick the method that matches what you are measuring — scrollable client area often maps to .innerWidth().

Example 4 — Callback Setter: Shrink Inner Width by 15px

Each click reduces the panel’s inner width by 15 pixels, with a minimum of 80px.

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

How It Works

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

Example 5 — Horizontal Scroll Track: fitTrack() with .innerWidth()

Set the scroll track’s inner width to fill the row beside a fixed label, recalculating on resize.

jQuery
function fitTrack() {
  var rowW = $( "#row" ).innerWidth();
  var labelW = $( "#label" ).outerWidth( true );
  $( "#track" ).innerWidth( Math.max( 120, rowW - labelW ) );
}
fitTrack();
$( window ).on( "resize", fitTrack );
Try It Yourself

How It Works

$("#row").innerWidth() gives the row’s padded inner width; $("#label").outerWidth(true) includes the label’s margin. The remainder is passed to .innerWidth() on the track so its padded inner box exactly fills the available space — a common tag bar and split-layout pattern.

🚀 Common Use Cases

  • Horizontal scroll tracks$("#track").innerWidth(rowW - labelW) to fill remaining row space with a scroll area.
  • Padded card sizing — when CSS padding is fixed, .innerWidth() targets the visible inner box including that padding.
  • Dimension debugging — compare .width(), .innerWidth(), and .outerWidth() to trace box-model mismatches.
  • Shrink-on-click UI — callback setter .innerWidth(function(i, w){ return w - 15; }) for interactive panels.
  • Equal inner widths — read each card’s .innerWidth(), find the max, set all to match padded columns.
  • Animation targets — pair measured .innerWidth() with .animate() when padding must stay inside the animated box.

🧠 How .innerWidth() Reads and Writes Dimensions

1

Match elements

jQuery object holds DOM elements — not window or document.

Input
2

Detect mode

No args → getter. Number or function → setter on each element (1.8+).

Route
3

Measure or apply

Getter reads clientWidth (content + padding). Setter adjusts CSS width to hit the target inner 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 — border and margin excluded.
  • 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.
  • Values can be fractional (e.g. 142.5) on sub-pixel or zoomed displays.
  • Setter returns the original jQuery object — e.g. .innerWidth(120).addClass("mod").

Browser Support

.innerWidth() getter has been part of jQuery since 1.2.6+. Setter and callback forms arrived in 1.8+. It wraps cross-browser reads of clientWidth (content plus padding) with no browser-specific quirks beyond jQuery itself.

jQuery 1.2.6+

jQuery .innerWidth()

Supported in jQuery 1.x, 2.x, and 3.x across all modern browsers and IE with supported jQuery builds. Native equivalent: element.clientWidth — jQuery adds collection semantics, unitless Numbers, 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
.innerWidth() Universal

Bottom line: Safe in any jQuery project. Use .innerWidth() when padding belongs in the measurement; use .width() for content-only or window/document reads.

Conclusion

The jQuery .innerWidth() method gets or sets element width including padding as a unitless pixel Number — the right dimension helper when the padded inner box matters for horizontal scroll areas, cards, and layout math. It sits between .width() (content only) and .outerWidth() (padding plus border).

Remember the official demo: $( "p" ).first().innerWidth() reads padded inner width, and the setter .innerWidth(60) targets the full inner box. Use the callback form to shrink or grow per element, and pair .innerWidth() with row and label measurements for horizontal scroll tracks — but never call .innerWidth() on window or document directly.

💡 Best Practices

✅ Do

  • Use .innerWidth() when padding must be included in the measurement
  • Use .innerWidth(value) to size scroll tracks to a pixel target
  • Use the callback setter for shrink/grow patterns based on current inner width
  • Combine $("#row").innerWidth() with .outerWidth(true) on siblings for split layouts
  • Reach for .outerWidth() when border width also affects layout

❌ Don’t

  • Call .innerWidth() on $(window) or $(document)
  • Trust .innerWidth() on display:none elements — it may return 0
  • Assume .innerWidth() includes border — use .outerWidth() instead
  • Expect the getter to read all matched elements — only the first
  • Forget that an empty jQuery set returns undefined from the getter

Key Takeaways

Knowledge Unlocked

Six things to remember about .innerWidth()

Padded inner box — ready for math.

6
Core concepts
= 02

Setter

1.8+

Write
pad 03

+ Padding

Included

Box
fn 04

Callback

1.8+

Index
el 05

Elements

Not window

Scope
hide 06

Hidden

Unreliable

Caveat

❓ Frequently Asked Questions

Calling .innerWidth() with no arguments is the getter — it returns the current width of the first matched element as a unitless Number (pixels), including padding but excluding border and margin. Calling .innerWidth(value) or .innerWidth(function) is the setter — it sets the CSS width on every matched element so that the inner width (content plus padding) equals the value you pass, and returns the original jQuery object for chaining. The getter has been available since jQuery 1.2.6; setters arrived in 1.8.
Yes to horizontal padding — .innerWidth() measures the content box plus left and right padding, equivalent to clientWidth without scrollbar height. It does not include border or margin. For the full box including border, use .outerWidth(); pass true to .outerWidth(true) to add margin as well. For content width only (no padding), use .width().
.width() returns content width only — padding and border excluded. .innerWidth() adds horizontal padding on top of content. .outerWidth() adds padding and border (and optionally margin). All three return unitless Numbers for getters. .innerHeight() is the vertical counterpart — same box-model rules but for height. .css('width') is a general CSS getter that returns a string such as '120px' or 'auto' — use it when you need literal CSS values or percentage widths, not for quick pixel math.
No — .innerWidth() is for elements only. Unlike .width(), which works on $(window) and $(document), .innerWidth() does not support window or document objects. For viewport width use $(window).width(); for full page scroll width use $(document).width(). Use .innerWidth() when you need the padded inner box of a DOM element such as a horizontal scroll track or sidebar panel.
The getter .innerWidth() has been available since jQuery 1.2.6. The setter .innerWidth(value) and the callback form .innerWidth(function(index, width)) were both added in jQuery 1.8. The callback receives the zero-based index and the element's current inner width; return a new Number to set each element's inner width independently — useful for shrink-on-click panels and staggered column layouts.
Calling .innerWidth() on an empty jQuery set returns undefined — there is no first element to measure. On display:none or visibility:hidden elements, .innerWidth() 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. 142.5) on sub-pixel layouts or zoomed displays; use Math.round() when you need integers for layout.
Did you know?

jQuery’s .innerWidth() getter has existed since version 1.2.6 — long before setters arrived in 1.8. It maps closely to the native clientWidth property: content plus padding, no border. On a typical element with 16px horizontal padding, .innerWidth() reads roughly 32px wider than .width(). The callback setter mirrors .width() and .height() — return a different inner width per index for shrink panels and staggered layouts. For split-row math, combine $("#row").innerWidth() with sibling .outerWidth(true), but never call .innerWidth() on the window object itself.

Next: .outerWidth()

Learn width including padding, border, and optional margin.

.outerWidth() 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