Favorites

DOM Window: resize event

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
Window: resize event
DOM Window EventThis event is supported by all modern browsers.
Updated 28th November 2026

The resize event fires on the window whenever the viewport changes size.

Description

The resize event fires when the viewport is resized, including when a phone is rotated. It can fire many times a second while dragging, so keep the handler light or throttle it. To react to breakpoints, matchMedia() is more efficient, and to watch a particular element's size, use ResizeObserver.

A simple way to limit work is to schedule it with requestAnimationFrame() or a short setTimeout() debounce, so heavy calculations run at most once per frame or once the user stops resizing. Mobile browsers can fire resize when the address bar shows or hides, so don't assume it only fires when the window is dragged.

Listeners for window events are added with window.addEventListener(). The older way, assigning a function to a property such as window.onresize, only allows one handler, so a second assignment replaces the first.

Syntax

window.addEventListener('resize', handler)

Example

<p>Viewport: <strong id="size"></strong></p>
const out = document.getElementById('size');
function show() { out.textContent = innerWidth + ' x ' + innerHeight; }
window.addEventListener('resize', show);
show();
console.log('Resize the browser window to see updates');

Browser Support

The following information will show you the current browser support for the Window: resize event event. Hover over a browser icon to see the version that first introduced support for this event.

This event is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee