JavaScript Window resizeTo() Method

Beginner
⏱️ 7 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
Exact size

What You’ll Learn

The resizeTo() method sets a browser window to exact outer width and height in pixels. This tutorial covers syntax, how it differs from resizeBy(), pairing with window.open(), popup usage, browser restrictions, five examples, and when not to use it.

01

Syntax

resizeTo(w, h)

02

Absolute

Exact dimensions

03

vs resizeBy

Relative delta

04

Popups

popup.resizeTo()

05

open()

Initial size string

06

Limits

Often blocked

Introduction

Sometimes you need a window at a specific size—a compact tool palette, a fixed preview pane, or a popup dialog with predictable dimensions. The window.resizeTo() method sets the outer width and height of the current window to exact pixel values.

Like resizeBy(), moveTo(), and moveBy(), resize APIs are limited on tabs the user opened themselves. Browsers prevent sites from resizing the user’s main window unexpectedly. Test with popups created via window.open(), especially when the user clicks a button to trigger the resize.

Understanding the resizeTo() Method

window.resizeTo(width, height) takes two numbers and returns undefined. The browser attempts to set the window’s outer width and height—the full window frame including chrome—to those values.

The viewport (the page area) is smaller than the outer size because of toolbars and borders. Read innerWidth / innerHeight for content area dimensions and outerWidth / outerHeight for the full window frame.

💡
Beginner Tip

Think of resizeTo as “set to this size” and resizeBy as “grow or shrink from here.” For layout inside a page, size elements with CSS—not the browser window.

📝 Syntax

General form of Window.resizeTo():

JavaScript
window.resizeTo(width, height);
// resize a popup reference:
popupWindow.resizeTo(640, 480);

Parameters

  • width — target outer width in pixels.
  • height — target outer height in pixels.

Return value

  • undefined.

Related APIs

  • window.resizeBy(dw, dh) — change size by a relative delta.
  • window.open(url, name, "width=640,height=480") — set initial popup size at open time.
  • window.outerWidth / outerHeight — full window frame size.
  • window.innerWidth / innerHeight — viewport (content area) size.
  • window.moveTo(x, y) — set absolute position (also restricted).

⚡ Quick Reference

TopicDetail
Set exact sizewindow.resizeTo(w, h)
Resize popuppopupRef.resizeTo(w, h)
Common presetresizeTo(800, 600)
Relative adjustresizeBy(dw, dh) instead
Size at openopen(..., "width=…,height=…")
Main user tabOften cannot resize

📋 resizeTo() vs resizeBy() vs open()

Choose absolute sizing, relative adjustment, or initial size when the popup opens.

resizeTo
resizeTo(640, 480)

Set outer size exactly

resizeBy
resizeBy(50, 30)

Grow from current size

open()
width=640,height=480

Initial popup dimensions

CSS
max-width, flex

In-page responsive layout

Examples Gallery

Use the Try-it links to set window size from button clicks. Popups opened with window.open() are the most reliable way to see resizeTo() work.

📚 Getting Started

Set the window to a fixed outer size in one call.

Example 1 — Set Window to 800×600

A classic desktop-friendly window size.

JavaScript
window.resizeTo(800, 600);
console.log("resizeTo(800, 600) called — may be blocked on main tabs.");
Try It Yourself

How It Works

The method runs immediately; the browser decides whether the window may actually change size. On a normal tab the request is often ignored.

📈 Practical Patterns

User-triggered sizing, popups, open() integration, and reading dimensions.

Example 2 — Resize on Button Click

Offer preset sizes the user can choose.

JavaScript
document.getElementById("compactBtn").addEventListener("click", function () {
  window.resizeTo(480, 360);
  console.log("Compact size: 480×360");
});

document.getElementById("largeBtn").addEventListener("click", function () {
  window.resizeTo(1024, 768);
  console.log("Large size: 1024×768");
});
Try It Yourself

How It Works

Preset buttons give users control over window size instead of resizing automatically—which browsers and users prefer.

Example 3 — Opener Sets Popup Size with resizeTo()

Store the open() reference and resize the child window.

JavaScript
let popupWindow = null;

document.getElementById("openBtn").onclick = function () {
  popupWindow = window.open("", "SizeDemo", "width=320,height=200,left=200,top=120");
  popupWindow.document.write("<p>Resize me from the opener</p>");
};

document.getElementById("resizePopupBtn").onclick = function () {
  if (popupWindow && !popupWindow.closed) {
    popupWindow.resizeTo(500, 400);
    console.log("Popup set to 500×400.");
  }
};
Try It Yourself

How It Works

Open small, then expand when the user needs more space. Combine with moveTo() to reposition after resizing.

Example 4 — Initial Size with open(), Then resizeTo()

Set dimensions in the features string at open time, or adjust later.

JavaScript
const popup = window.open(
  "https://example.com",
  "ExamplePopup",
  "width=600,height=400,scrollbars=yes"
);

// Later, if still open:
if (popup && !popup.closed) {
  popup.resizeTo(800, 600);
}
Try It Yourself

How It Works

For new popups, specifying width and height in open() is often enough. Use resizeTo() when you need to change size after the window already exists.

Example 5 — Log Outer and Inner Dimensions

Compare frame size with viewport size after calling resizeTo().

JavaScript
window.resizeTo(640, 480);

console.log(`Outer: ${window.outerWidth}×${window.outerHeight}`);
console.log(`Inner: ${window.innerWidth}×${window.innerHeight}`);
Try It Yourself

How It Works

resizeTo targets outer dimensions. The inner viewport is always smaller because of browser UI. If resize is blocked, logged values stay unchanged.

🚀 Common Use Cases

  • Popup dialogs — fixed-size helper windows for tools or wizards.
  • Preview panes — expand a popup when showing detailed content.
  • Preset layouts — Compact / Standard / Large buttons for script-opened windows.
  • Legacy desktop-style apps — floating palettes with known dimensions.
  • Post-open adjustment — resize after window.open() when content needs more room.
  • Learning demos — teaching window APIs alongside resizeBy and moveTo.

🧠 What Happens When You Call resizeTo()

1

Pass dimensions

Script supplies target outer width and height in pixels.

Args
2

Policy check

Browser verifies the window may be resized.

Security
3

Set outer size

Window frame adjusts to the requested dimensions (within min/max limits).

Absolute
4

Viewport updates

Inner content area reflows; method returns undefined.

📝 Notes

  • resizeTo sets outer size, not viewport (innerWidth) directly.
  • Do not auto-resize on page load or on every resize event—it frustrates users and is usually blocked.
  • Checking if (window.resizeTo) is not useful—the method exists everywhere; policy decides if it works.
  • Maximized and fullscreen windows may ignore resize requests.
  • Mobile browsers often lack resizable windows; popups may open as tabs.
  • For in-page layout, use CSS media queries and flexible grids—not resizeTo().

Browser Support

Window.resizeTo() exists in all major browsers, but whether resizing succeeds depends on window type and browser policy—not on missing API support.

Universal API · Restricted behavior

Window.resizeTo()

The method is available in Chrome, Firefox, Safari, Edge, and Opera. Script-opened popups resize most reliably; user-opened main tabs are often protected.

100% API availability
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
resizeTo() Universal

Bottom line: Test with popups from window.open() during user clicks. Never rely on resizing the user's primary tab.

Conclusion

window.resizeTo() sets a browser window to exact outer dimensions. It complements resizeBy() and pairs naturally with window.open() for popup workflows.

Trigger resizes from user actions, prefer CSS for page layout, and test on script-opened popups. When you only need a small adjustment, reach for resizeBy() instead.

💡 Best Practices

✅ Do

  • Use resizeTo on popups you opened with window.open()
  • Trigger resizes from button clicks when possible
  • Set initial size in open() features when opening popups
  • Log outerWidth and innerWidth to understand chrome overhead
  • Use resizeBy() for small step adjustments

❌ Don’t

  • Resize the user’s main tab without clear consent
  • Call resizeTo inside a window resize listener
  • Use resizeTo for responsive page layout
  • Assume innerWidth equals the width you pass to resizeTo
  • Auto-resize windows on every page load

Key Takeaways

Knowledge Unlocked

Five things to remember about resizeTo()

Your foundation for setting exact window size in JavaScript.

5
Core concepts
📐 02

Absolute

Exact outer size.

Pixels
🚫 03

Restricted

Main tab blocked.

Policy
🔌 04

Popups

popup.resizeTo

open()
📍 05

vs resizeBy

Relative delta.

Pair

❓ Frequently Asked Questions

It sets the outer width and height of the current window to exact pixel values. resizeTo(800, 600) attempts to make the window 800px wide and 600px tall—including browser chrome such as the title bar.
resizeTo(width, height) sets absolute dimensions. resizeBy(deltaWidth, deltaHeight) adjusts from the current size. Use resizeTo when you know the target size; use resizeBy for small grow/shrink steps.
No. Modern browsers restrict programmatic window resizing. resizeTo() may be ignored on tabs the user opened directly. It works more reliably on popups your script opened with window.open().
No. It returns undefined. Read window.outerWidth, outerHeight, innerWidth, or innerHeight if you need to inspect dimensions after calling it.
No. Responsive layout belongs in CSS and flexible DOM design. Calling resizeTo() inside a resize listener fights the user and is usually blocked on main tabs.
Pass width and height in the window.open() features string, e.g. open(url, name, "width=640,height=480"). Use resizeTo() later if you need to change an already-open popup.
Did you know?

The width and height in a window.open() features string set the initial popup size—resizeTo() is what you call when you need to change dimensions after the window is already open.

Continue to scrollBy()

Learn how to scroll the page by a relative offset with the window.scrollBy() method.

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

6 people found this page helpful