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
Fundamentals
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.
Concept
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.
Foundation
📝 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.
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.");
}
};
Outer: 640×480
Inner: 624×412
(inner values vary by browser chrome; unchanged if resize blocked)
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.
Applications
🚀 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.
Important
📝 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().
Compatibility
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 ChromeAll versions · Desktop & Mobile
Full support
Mozilla FirefoxAll versions · Desktop & Mobile
Full support
Apple SafariAll versions · macOS & iOS
Full support
Microsoft EdgeAll versions · Chromium & Legacy
Full support
Internet ExplorerIE 6+ · Legacy environments
Full support
OperaAll 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.
Wrap Up
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.
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
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about resizeTo()
Your foundation for setting exact window size in JavaScript.
5
Core concepts
📝01
Syntax
resizeTo(w, h)
API
📐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.