jQuery resize Event

Beginner
7 min read
Updated: Oct 2026
5 examples
Live preview

What Is resize?

The resize event is sent to the window when the browser viewport changes size. Bind it with $(window).on("resize", handler) (since jQuery 1.7). Trigger it with .trigger("resize").

Remember
$(window).on("resize", function () {
  // viewport size changed
});

$(window).trigger("resize"); // fire handlers programmatically

// Do not rely on how many times the handler runs
// Debounce expensive layout / chart work
NeedUse
Listen for viewport change$(window).on("resize", fn)
Read current width$(window).width()
Fire handlers now$(window).trigger("resize")
Heavy workDebounce / throttle inside the handler
Legacy shorthand.resize() ⚠

How to Use resize

Bind on window, keep the handler light, and debounce anything expensive.

  1. Attach with $(window).on("resize", handler).
  2. Read size with $(window).width() / .height() inside the handler.
  3. Debounce or throttle layout recalculation and DOM-heavy work.
  4. Call $(window).trigger("resize") when your code changes layout without a real resize.
  5. Remove with $(window).off("resize", handler) when cleaning up.
PieceRequired?Role
windowYesStandard target for viewport resize
handlerYesfunction(event)
eventDataOptionalExtra data as event.data
DebounceRecommendedLimit how often expensive work runs

Pseudocode

Pseudocode
bind resize on window with handler(event)

when browser viewport size changes:
    fire resize on window
        for each registered handler:
            call handler(event)
            // may fire many times during a drag

when your code needs the same logic:
    trigger resize on window

for expensive work:
    on each resize:
        clear previous timer
        start timer (e.g. 200ms)
        when timer ends: run layout / redraw

Cheat Sheet

Keep these facts handy while wiring viewport-aware UI.

TopicDetail
Bind$(window).on("resize", handler)
Unbind$(window).off("resize" [, handler])
Trigger$(window).trigger("resize")
Signaturefunction(event)
WhenBrowser window size changes
Since.on() form 1.7 · trigger 1.0
Call countBrowser-dependent — do not rely on it
Width / height$(window).width() / .height()

Live Preview

Resize the browser (or click Trigger) and watch the resize handler update the log.

Tip: drag the browser edge to fire real resize events, or use Trigger.

Result
Ready — resize the window or click Run.

jQuery Examples

Short, copy-ready snippets. Resize the preview window, or use Try It Yourself for a live editor.

Example 1 — Append to #log

Official pattern: append a short message each time resize fires.

jQuery
$(window).on("resize", function () {
  $("#log").append(" Handler for resize called. ");
});
Try It Yourself

How It Works

  1. Bind. .on("resize") on window listens for viewport changes.
  2. Resize. The browser fires the event when the window size changes.
  3. Append. Each firing adds another message fragment.
  4. Count. Do not assume a fixed number of calls per drag.

Example 2 — Show Window Width

Official demo: prepend the current $(window).width() on each resize.

jQuery
$(window).on("resize", function () {
  $("body").prepend($(window).width() + " ");
});
Try It Yourself

How It Works

  1. Listen. The handler runs on every resize event.
  2. Measure. $(window).width() reads the current viewport width.
  3. Prepend. New values are inserted at the top of body.
  4. Use. Handy for quick debugging of responsive breakpoints.

Example 3 — Debounce Expensive Work

Wait until resizing pauses before recalculating layout.

jQuery
var timer;

function recalcLayout() {
  $("#box").text("Width: " + $(window).width() + "px");
}

$(window).on("resize", function () {
  clearTimeout(timer);
  timer = setTimeout(recalcLayout, 200);
});
Try It Yourself

How It Works

  1. Raw events. Resize can fire many times during a drag.
  2. Reset timer. Each event clears the previous timeout.
  3. Settle. Work runs only after 200ms of quiet.
  4. Use. Ideal for charts, masonry, and heavy DOM updates.

Example 4 — Trigger Programmatically

Fire bound handlers with .trigger("resize") without resizing the window.

jQuery
$(window).on("resize", function () {
  $("#log").text("Width: " + $(window).width() + "px");
});

$("#run").on("click", function () {
  $(window).trigger("resize");
});
Try It Yourself

How It Works

  1. Bind. The same handler listens for real and synthetic events.
  2. Click. .trigger("resize") fires the event on window.
  3. Update. The log shows the current width.
  4. When. Use after JS changes panel sizes or toggles a sidebar.

Example 5 — Breakpoint with eventData

Pass a breakpoint via event data and update UI when width crosses it.

jQuery
function applyBreakpoint(bp) {
  var w = $(window).width();
  $("#status").text(
    w < bp ? "Narrow (< " + bp + "px)" : "Wide (≥ " + bp + "px)"
  );
}

$(window).on("resize", { breakpoint: 480 }, function (event) {
  applyBreakpoint(event.data.breakpoint);
});

applyBreakpoint(480);
Try It Yourself

How It Works

  1. Data. { breakpoint: 480 } becomes event.data.
  2. Measure. Compare $(window).width() to that threshold.
  3. Update. Status text switches between narrow and wide.
  4. Init. Call once on load so the first paint is correct.

Edge Cases & Pitfalls

Check these before shipping viewport-sensitive UI.

target

Bind on window

Viewport resize is delivered to window. Prefer $(window).on("resize", fn).

count

Do not rely on call count

Some browsers fire continuously during a drag; others once at the end. Debounce instead.

cost

Heavy work on every resize hurts

Measuring the whole DOM or redrawing charts on every event can jank the page — debounce first.

deprecated

Prefer .on() over .resize()

.resize(handler) is deprecated since 3.3. New code should use .on("resize").

Browser Support

The resize event is a native browser event. Prefer $(window).on("resize", …) (jQuery 1.7+). Trigger with .trigger("resize") since 1.0.

✓ Stable · jQuery 1.7+

jQuery resize

Works in every browser that runs your loaded jQuery version. Call frequency during a drag varies by engine — design handlers accordingly.

100% Browser event
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
resize Universal

Bottom line: Safe for everyday apps. Bind on window, debounce expensive work, and prefer .on('resize') over deprecated .resize().

Performance Notes

ApproachCostBest for
Light log / width readCheapDebugging, simple labels
Debounced layout / chart redrawCheap–moderateResponsive UI updates
Heavy DOM work every resizeExpensiveAvoid — debounce or throttle

Resize handlers are fine when they stay light. Measure once after settling, then update the DOM — do not reflow on every pixel of drag.

Key Takeaways

  • Role: viewport size changed — recalculate responsive UI.
  • Bind: $(window).on("resize", fn) — prefer window.
  • Debounce: expensive work should wait until resizing pauses.
  • Trigger: use .trigger("resize") after JS layout changes.

One line: resize is the window’s size-changed event — bind it with .on() and debounce heavy work.

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. 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. Always target window for viewport resize handling.
Browser behavior varies. In Internet Explorer and WebKit, resize may fire continuously while the user drags. In some other browsers 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.
Call $(window).trigger("resize"). Bound resize handlers on window run as if the viewport changed — useful when your code changes layout dimensions without the user resizing the browser.
The shorthand method .resize(handler) is deprecated as of jQuery 3.3 (it still works in 3.x). Prefer $(window).on("resize", handler) — the event API this page teaches. See the .resize() shorthand page for migration notes.

Next: .resize() method

See the deprecated shorthand and how to migrate to .on("resize").

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

8 people found this page helpful