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
Bind on window, keep the handler light, and debounce anything expensive.
Attach with $(window).on("resize", handler).
Read size with $(window).width() / .height() inside the handler.
Debounce or throttle layout recalculation and DOM-heavy work.
Call $(window).trigger("resize") when your code changes layout without a real resize.
Remove with $(window).off("resize", handler) when cleaning up.
Piece
Required?
Role
window
Yes
Standard target for viewport resize
handler
Yes
function(event)
eventData
Optional
Extra data as event.data
Debounce
Recommended
Limit 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
Reference
Cheat Sheet
Keep these facts handy while wiring viewport-aware UI.
Topic
Detail
Bind
$(window).on("resize", handler)
Unbind
$(window).off("resize" [, handler])
Trigger
$(window).trigger("resize")
Signature
function(event)
When
Browser window size changes
Since
.on() form 1.7 · trigger 1.0
Call count
Browser-dependent — do not rely on it
Width / height
$(window).width() / .height()
Try it
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.
Code
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. ");
});
Bind. The same handler listens for real and synthetic events.
Click..trigger("resize") fires the event on window.
Update. The log shows the current width.
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);
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.