The resize event fires when the browser window changes size. This tutorial covers .on("resize") on $(window), logging viewport width, debouncing expensive layout work, .trigger("resize"), the official jQuery API demos, and how this differs from scroll, orientationchange, and the removed .resize() method.
01
.on()
Bind handler
02
$(window)
Viewport target
03
.width()
Log size
04
Debounce
Throttle work
05
.trigger()
Fire resize
06
Since 1.7
Modern API
Fundamentals
Introduction
Responsive dashboards, fluid grids, and chart libraries all need to know when the viewport changes. The resize event is jQuery’s hook for that moment — when the browser window grows, shrinks, or the user finishes dragging an edge.
The official jQuery API distinguishes the resizeevent (bound with .on("resize") since 1.7 on $(window)) from the removed .resize()method (legacy shorthand, gone in jQuery 3.0). To programmatically run resize handlers, use .trigger("resize") since jQuery 1.0.
Concept
Understanding the resize Event
The resize event is sent to the window element when the browser window size changes. jQuery wraps the native event so you can bind with $(window).on("resize", handler) and chain further calls on the same collection.
Resize behavior differs by browser: in Internet Explorer and WebKit it may fire continuously while the user drags a window edge; in Opera it may fire only once when resizing finishes. Never assume a fixed number of calls — debounce or throttle layout work instead.
💡
Beginner Tip
Always bind on $(window), not document or body. The jQuery API sends resize to the window object when the browser viewport changes size.
Foundation
📝 Syntax
The modern jQuery API for the resize event has two main forms — binding a handler and triggering the event:
jQuery also provided .resize(handler) as a legacy binding shorthand and no-arg .resize() to trigger the event. The binding form is deprecated since jQuery 3.3 — see the jQuery .resize() method tutorial or migrate to .on("resize") and .trigger("resize").
Return value
.on() and .trigger() return the original jQuery object for chaining.
Inside the handler, this refers to the window DOM element — use $(window).width() and $(window).height() for viewport dimensions.
Cheat Sheet
⚡ Quick Reference
Goal
Code
Bind resize handler on window
$(window).on("resize", fn)
Log viewport width on resize
$(window).width() inside handler
Append resize log lines
$("#log").append("<div>...</div>")
Debounce expensive layout work
clearTimeout(t); t = setTimeout(fn, 150)
Pass breakpoint config
$(window).on("resize", { bp: 768 }, fn)
Trigger resize programmatically
$(window).trigger("resize")
Remove resize handlers
$(window).off("resize")
Compare
📋 resize vs scroll vs orientationchange vs deprecated .resize()
Four related concepts that sound similar — know which reacts to viewport size, element scrolling, device rotation, and legacy jQuery shorthand.
resize event
window
Browser viewport size changed — bind with .on("resize") on $(window); may fire continuously or once depending on browser
scroll event
element
An element’s scroll position changed — fires on window, document, or overflow containers; not the same as viewport resize
orientationchange
mobile
Device orientation flipped — often paired with resize on phones; some layouts need both handlers
.resize() method
removed
Legacy bind (.resize(fn)) or trigger (.resize()) — deprecated since 3.3; use .on("resize") and .trigger("resize") in new code
Hands-On
Examples Gallery
Examples 1–2 follow the official jQuery API documentation. Examples 3–5 extend the pattern with debounced layout recalc, programmatic triggers, and responsive breakpoint classes via eventData. Use the Try-it links to run each snippet in the browser.
📚 Official API Demos
Official jQuery demos for logging resize and reading viewport width.
Example 1 — Official Demo: Append to #log on Resize
Log each resize call — from the jQuery API documentation.
Page loads → handler bound on $(window)
Resize browser window → #log gains new lines:
Handler for resize called.
May fire many times while dragging (IE/WebKit) or once (Opera)
How It Works
Binding on $(window) catches every viewport size change. Appending to #log makes the firing pattern visible — resize the Try-it panel to see continuous vs single-fire behavior.
Example 2 — Official Demo: Prepend $(window).width() on Resize
Log handler calls and the current viewport width — official jQuery API pattern.
Resize window → #log prepends:
window width is 1024
Handler for resize called.
Width updates to match $(window).width() on each fire
How It Works
$(window).width() returns the viewport width in pixels at the moment the handler runs. Prepending keeps the newest measurements at the top of the log for easy comparison while resizing.
📈 Production Patterns
Debounce heavy work, trigger resize manually, and pass breakpoint config with eventData.
Example 3 — Debounced Layout Recalculation
Wait until resizing pauses before recalculating layout — avoids jank when resize fires continuously.
jQuery
var resizeTimer;
function recalcLayout() {
var w = $( window ).width();
$( "#panel" ).css( "width", Math.min( w - 40, 600 ) );
$( "#log" ).append( "<div>Layout recalc at width " + w + "</div>" );
}
$( window ).on( "resize", function() {
clearTimeout( resizeTimer );
resizeTimer = setTimeout( recalcLayout, 150 );
} );
Drag-resize window rapidly → few log lines, not hundreds
After 150 ms pause → one "Layout recalc at width …" entry
#panel width updates once per settled resize
How It Works
clearTimeout plus setTimeout collapses many resize events into one layout pass. This is the standard pattern for charts, masonry grids, and any DOM measurement that would stutter if run on every intermediate pixel.
Example 4 — Button Triggers .trigger("resize")
Fire resize handlers programmatically when your code changes layout without a browser resize.
Click Trigger resize → trigger("resize") runs bound handler
#log appends: Handler for resize called.
Useful after toggling a sidebar or injecting content that changes layout
How It Works
.trigger("resize") synthetically fires the event. Bound handlers run even though the browser viewport did not change — ideal when your own code alters dimensions and downstream widgets expect a resize notification.
Example 5 — eventData Breakpoint Responsive Class
Pass a breakpoint via eventData and toggle a responsive class on body when width crosses the threshold.
Viewport < 768px → body gets is-narrow, log shows Mode: narrow (bp 768)
Viewport ≥ 768px → body gets is-wide, log shows Mode: wide (bp 768)
event.data.breakpoint available inside handler without closure variables
How It Works
The second argument to .on("resize", data, fn) becomes event.data inside the handler. Multiple handlers can share the same function with different breakpoint objects — cleaner than hard-coding values in each callback.
Applications
🚀 Common Use Cases
Responsive layout sync — recalculate column widths, sidebar visibility, or grid breakpoints when the viewport changes.
Chart and canvas redraw — resize D3, Chart.js, or custom canvas drawings to fit the new window dimensions.
Sticky header offsets — remeasure fixed nav height after orientation or window changes on tablets.
Map widgets — call map.invalidateSize() or equivalent after container dimensions update.
Virtual scroll lists — recompute visible row counts when the viewport height changes.
Manual layout notifications — use .trigger("resize") after AJAX injects content that changes dimensions without a browser resize.
🚀 How the resize Event Flows
1
Handler bound on window
Code calls $(window).on("resize", fn) — optionally with eventData for breakpoints or config objects.
bind
2
Viewport size changes
The user drags a window edge, toggles devtools, or rotates a device. The browser sends resize to the window object — continuously or once depending on engine.
native
3
Handler runs (maybe many times)
jQuery invokes your callback. Read $(window).width(), update CSS classes, or queue debounced layout work — never assume a fixed call count.
handler
4
📐
Layout stays in sync
UI reflects the new viewport. For programmatic changes, call $(window).trigger("resize") so widgets that only listen for resize also update.
Important
📝 Notes
Bind with .on("resize", handler) since jQuery 1.7 — not the removed .resize() shorthand.
Trigger with .trigger("resize") since jQuery 1.0.
Attach handlers on $(window) — the event is sent to the window element when the browser window size changes.
In IE and WebKit, resize may fire continuously while dragging; in Opera it may fire once at the end — never rely on call count.
Debounce or throttle expensive layout, chart, and measurement code inside resize handlers.
resize is not scroll — scroll fires when content position changes inside scrollable elements.
On mobile, consider pairing with orientationchange for rotation-specific layout.
Use .off("resize") to remove handlers — avoid deprecated .unbind("resize") or removed .resize().
Compatibility
Browser Support
The resize event is a standard DOM event on window, supported in every browser jQuery targets. jQuery’s .on("resize") (since 1.7) and .trigger("resize") (since 1.0) provide consistent binding and chaining. Firing frequency during drag varies by engine — debounce production handlers.
✓ jQuery 1.7+
jQuery resize event
Supported in jQuery 1.x, 2.x, and 3.x across all modern browsers and IE with supported jQuery versions. Native equivalent: window.addEventListener('resize', fn) — jQuery adds collection binding, eventData, and .trigger() in one chainable API.
100%With jQuery loaded
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
resizeUniversal
Bottom line: Safe in any jQuery project. Prefer .on('resize') over the removed .resize() method. Bind on $(window) and debounce heavy work.
Wrap Up
Conclusion
The jQuery resize event is the standard hook for viewport size changes. Bind handlers with $(window).on("resize", fn), read dimensions with $(window).width(), debounce expensive layout work, and fire handlers programmatically with .trigger("resize").
Remember: firing frequency varies by browser during drag, this is not the scroll event, and the legacy .resize() shorthand is deprecated since jQuery 3.3. For mobile rotation, pair with orientationchange where needed.
Debounce or throttle layout recalc, charts, and DOM measurements
Use eventData to pass breakpoint config into handlers
Call .trigger("resize") after your code changes layout dimensions
Remove handlers with .off("resize") when widgets unmount
❌ Don’t
Confuse with removed .resize() — migrate to .on("resize")
Bind on document or body expecting viewport resize
Assume resize fires exactly once per user drag — count varies by browser
Run heavy synchronous work on every resize fire without debouncing
Confuse resize with scroll or orientationchange
Summary
Key Takeaways
Knowledge Unlocked
Six things to remember about the resize event
Window, width, debounce.
6
Core concepts
.on01
.on("resize")
Bind
API
win02
$(window)
Target
Element
W03
.width()
Viewport
Measure
⏱04
Debounce
No jank
Perf
⚡05
.trigger()
Manual
Programmatic
≠06
Not scroll
Viewport
Compare
❓ Frequently Asked Questions
The resize event is sent to the window element when the browser viewport changes size — for example when the user drags a window edge or rotates a device. Bind with $(window).on('resize', handler) since jQuery 1.7. It is a browser event, not an Ajax callback; use it to recalculate layouts, update charts, or sync UI to the current viewport width and height.
The official jQuery API sends resize to the window object when the browser window size changes. $(window).on('resize', fn) is the standard pattern. Binding on document or body may not receive the native event consistently across browsers. Always target window for viewport resize handling.
Browser behavior varies. In Internet Explorer and WebKit, resize may fire continuously while the user drags a window edge. In Opera (classic behavior noted in the jQuery docs), it may fire only once when resizing finishes. Never rely on a specific call count — debounce or throttle expensive work instead.
Yes, for anything heavier than a simple log line. Because resize can fire many times per second during a drag, layout recalculation, chart redraws, and DOM measurements should run through debounce or throttle so your page stays responsive. Example 3 on this page shows a debounced layout recalc pattern.
Call $(window).trigger('resize') since jQuery 1.0. Bound resize handlers on window run as if the viewport changed — useful when your code changes layout dimensions without the user resizing the browser. Example 4 uses a button to fire trigger('resize') and append to #log.
They target the same browser resize event on window — .resize(handler) is the legacy shorthand deprecated since jQuery 3.3, while .on('resize', handler) is the modern replacement since 1.7. Unlike .error(), which was removed in jQuery 3.0, .resize() still works in jQuery 3.x but should not be used in new code. Do not confuse window resize with scroll or orientationchange.
Did you know?
The jQuery API page for resize notes that in Internet Explorer and WebKit the event may fire continuously while the user resizes the window, whereas in Opera it may fire only once when resizing finishes. That is why counting resize calls is unreliable — production code debounces layout work instead. The same page also documents that the event is sent to the window element, which is why $(window).on("resize", fn) is the canonical pattern rather than binding on arbitrary containers.