JavaScript Window resizeTo() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
Method

Definition

window.resizeTo() dynamically requests a new absolute outer size for the window (MDN). Use resizeBy() for a relative change.

Pass the required arguments shown below. Check return values and browser support before you rely on the result.

Syntax

Call window.resizeTo. Start with this line.

JavaScript
resizeTo(width, height)
CallWhat it does
resizeTo(width, height)Primary signature.
window.resizeTo(...)Call with the arguments your case needs.

Built into the browser. Call window.resizeTo(...) (or the global resizeTo(...)) — no import required.

Library declarations
JavaScript
resizeTo(width, height)

Parameters

ParameterDescription
widthRequired. New outerWidth in pixels
heightRequired. New outerHeight in pixels

Return Value

Return ValueDescription
*Always undefined

JavaScript Examples

Example 1 — Basic resizeTo

Request an absolute outer size of 800×600 pixels.

JavaScript
window.resizeTo(800, 600);
// same as: resizeTo(800, 600);
console.log("resizeTo(800, 600) called");
Try It Yourself

How It Works

  1. Pass width, then height. Integers in pixels.
  2. Browser may honor it. Only in allowed contexts.
  3. Log a note. Confirms the call ran.
  4. Check size after. Read outerWidth / outerHeight.

Example 2 — Return Value

resizeTo() always returns undefined.

JavaScript
const result = window.resizeTo(640, 480);
console.log(result);        // undefined
console.log(typeof result); // "undefined"
Try It Yourself

How It Works

  1. Store the call. Capture the return value.
  2. Log it. Always undefined.
  3. No success flag. Size change is not reported by the return.
  4. Use events. Listen for resize if you need confirmation.

Example 3 — vs resizeBy

Absolute target size vs relative nudge.

JavaScript
resizeTo(800, 600); // set exact outer size
resizeBy(40, 20);   // then grow by +40 × +20
// final intent ≈ 840 × 620 (if both succeed)
Try It Yourself

How It Works

  1. resizeTo first. Jumps to an absolute size.
  2. resizeBy next. Adjusts from whatever size you have now.
  3. Same restrictions. Both may be ignored on main tabs.
  4. Pick one intent. Exact size → resizeTo; small step → resizeBy.

Example 4 — Quarter of the Screen

MDN pattern: half of avail width × half of avail height.

JavaScript
window.resizeTo(
  window.screen.availWidth / 2,
  window.screen.availHeight / 2
);
Try It Yourself

How It Works

  1. Read avail size. See availWidth / availHeight.
  2. Divide by 2. Area becomes one quarter of the available screen.
  3. Pass to resizeTo. Browser may round to integers.
  4. Still restricted. Prefer a script-opened popup.

Example 5 — Resize a Popup

Open a child window, then call resizeTo on that reference.

JavaScript
const popup = window.open("", "demo", "width=320,height=200");
if (popup) {
  popup.document.write("

Popup

"); popup.document.close(); popup.resizeTo(500, 400); console.log("Asked popup to resize"); } else { console.log("Popup blocked"); }
Try It Yourself

How It Works

  1. Open from a click. Popups need a user gesture.
  2. Keep the reference. Call methods on popup.
  3. Call popup.resizeTo. Absolute size for that window.
  4. Handle blockers. If open returns null, show a message.

Browser Support

Window.resizeTo() is marked Baseline Widely available on MDN (since July 2015). Availability ≠ unrestricted resizing — user agents still limit when the request succeeds.

✓ Baseline · Widely available

resizeTo()

Request an absolute outer window size across modern browsers.

99% Core tag support
Chrome Yes
Full support (restricted)
Edge Yes
Full support (restricted)
Firefox Yes
Full support (restricted)
Safari Yes
Full support (restricted)
Opera Yes
Full support (restricted)
HTML element 100% supported

Bottom line: Safe to teach and call on popups. Do not build critical UX that requires resizing the user’s main tab.

Frequently Asked Questions

It requests a new absolute outer size for the window: resizeTo(width, height) sets outerWidth and outerHeight in pixels (including browser chrome).
No. MDN marks Window.resizeTo() as Baseline Widely available (since July 2015). It is not Deprecated, Experimental, or Non-standard — but browsers heavily restrict when it works.
Usually no. MDN notes you cannot resize a window or tab that was not created by window.open(), and you cannot resize when the window has multiple tabs.
resizeTo(w, h) sets an absolute size. resizeBy(dw, dh) changes size by a relative delta from the current size.
undefined. There is no success flag. Read outerWidth / outerHeight, or listen for the resize event, to see if anything changed.
Not always. MDN notes it might not resize synchronously, and on some environments (like mobile) it might not resize at all. Listen for the resize event to observe changes.

Next: scrollBy()

Scroll the page by a relative pixel delta.

scrollBy() →

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