JavaScript Window resizeBy() Method

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

What You’ll Learn

The resizeBy() method changes a browser window’s size by a relative pixel amount. This tutorial covers syntax, positive and negative deltas, how it differs from resizeTo(), popup usage, browser restrictions, five examples, and when not to use it.

01

Syntax

resizeBy(w, h)

02

Relative

From current size

03

vs resizeTo

Exact dimensions

04

Popups

popup.resizeBy()

05

Signs

+/− grow or shrink

06

Limits

Often blocked

Introduction

Every browser window has a width and height. The window.resizeBy() method grows or shrinks that window by a number of pixels—without you needing to calculate the final size. Pass 200 for width to add 200 pixels; pass -50 for height to remove 50 pixels.

Like moveBy() and moveTo(), 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 resizeBy() Method

window.resizeBy(deltaWidth, deltaHeight) adds deltaWidth to the window’s current outer width and deltaHeight to its outer height. Both arguments are numbers (pixels). The method returns undefined.

Important: the arguments are deltas, not target sizes. resizeBy(100, 50) means “grow by 100×50 pixels,” not “set width to 100.” To set an exact size, use resizeTo() instead.

💡
Beginner Tip

Think of resizeBy as “adjust from here” and resizeTo as “set to exact width and height.” For layout inside a page, resize elements with CSS—not the browser window.

📝 Syntax

General form of Window.resizeBy():

JavaScript
window.resizeBy(deltaWidth, deltaHeight);
// resize a popup reference:
popupWindow.resizeBy(50, 30);

Parameters

  • deltaWidth — pixels to add to width. Positive grows wider; negative shrinks.
  • deltaHeight — pixels to add to height. Positive grows taller; negative shrinks.

Return value

  • undefined.

Related APIs

  • window.resizeTo(width, height) — set absolute outer dimensions.
  • window.innerWidth / window.innerHeight — viewport size (content area).
  • window.outerWidth / window.outerHeight — full window including chrome.
  • window.open() — create a popup you may resize.
  • window.moveBy() — change position by a relative delta (also restricted).

⚡ Quick Reference

TopicDetail
Resize current windowwindow.resizeBy(dw, dh)
Resize popuppopupRef.resizeBy(dw, dh)
Grow wider 100pxresizeBy(100, 0)
Shrink shorter 40pxresizeBy(0, -40)
Exact dimensionsresizeTo(w, h) instead
Main user tabOften cannot resize

📋 resizeBy() vs resizeTo()

Both change window size; choose relative adjustment or absolute dimensions.

resizeBy
resizeBy(80, 40)

+80px wide, +40px tall

resizeTo
resizeTo(640, 480)

Set outer size exactly

Read size
innerWidth

Viewport dimensions

In-page UI
CSS flex/grid

Layout elements, not window

Examples Gallery

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

📚 Getting Started

Grow the window from its current size by a fixed delta.

Example 1 — Basic Relative Resize

Add 200 pixels to width and 100 pixels to height.

JavaScript
window.resizeBy(200, 100);
console.log("resizeBy(200, 100) called — may be blocked on main tabs.");
Try It Yourself

How It Works

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

📈 Practical Patterns

User-triggered resizes, popups, shrinking, and reading dimensions.

Example 2 — Resize on Button Click

Tie resizing to a user gesture—the pattern browsers prefer.

JavaScript
function resizeWindow() {
  window.resizeBy(100, 50);
  console.log("Window grown by (100, 50).");
}

document.getElementById("resizeBtn").addEventListener("click", resizeWindow);
Try It Yourself

How It Works

Each click adds another relative delta. Small steps feel less jarring than huge jumps if resizing is allowed.

Example 3 — Opener Resizes a Popup

Store the open() reference and call resizeBy on the child window.

JavaScript
let popupWindow = null;

document.getElementById("openBtn").onclick = function () {
  popupWindow = window.open("", "ResizeDemo", "width=320,height=200,left=200,top=120");
  popupWindow.document.write("<p>I am a resizable popup</p>");
};

document.getElementById("resizePopupBtn").onclick = function () {
  if (popupWindow && !popupWindow.closed) {
    popupWindow.resizeBy(60, 40);
    console.log("Popup resized by (60, 40).");
  }
};
Try It Yourself

How It Works

Open the popup first, then grow it step by step. Combine with moveBy() to reposition helper palettes.

Example 4 — Shrink with Negative Values

Negative deltas reduce width and height from the current size.

JavaScript
window.resizeBy(-80, -40);
console.log("Window shrunk by (80, 40) if allowed.");
Try It Yourself

How It Works

Browsers enforce minimum window sizes, so shrinking may stop once a limit is reached. This is normal—not an error thrown by JavaScript.

Example 5 — Log Viewport Size Before and After

Read innerWidth and innerHeight to inspect the content area after resizing.

JavaScript
const before = `${window.innerWidth}×${window.innerHeight}`;
window.resizeBy(50, 30);
const after = `${window.innerWidth}×${window.innerHeight}`;

console.log(`Before: ${before}`);
console.log(`After:  ${after}`);
Try It Yourself

How It Works

innerWidth measures the viewport—the page area inside the window chrome. If resize is blocked, before and after values stay the same even though the method ran.

🚀 Common Use Cases

  • Helper popups — expand a tool palette after the user opens it.
  • Step controls — Grow / Shrink buttons that call small resizeBy deltas.
  • Legacy desktop-style apps — floating windows built with window.open().
  • Preview windows — slightly enlarge a popup when showing extra detail.
  • Learning demos — teaching window APIs alongside moveBy and open.
  • Internal admin tools — controlled environments where popups are expected.

🧠 What Happens When You Call resizeBy()

1

Pass deltas

Script supplies width and height pixel changes (positive or negative).

Args
2

Policy check

Browser verifies the window may be resized.

Security
3

Add to size

Current outer dimensions plus deltas become the new size (within limits).

Relative
4

Window resizes (maybe)

If allowed, the window grows or shrinks; method returns undefined.

📝 Notes

  • Do not pass innerWidth as the first argument—that is a common mistake. Pass the change, e.g. resizeBy(100, 0).
  • Do not auto-resize windows on page load—it frustrates users and is usually blocked.
  • Maximized and fullscreen windows may ignore resize requests.
  • Mobile browsers often lack traditional resizable windows; popups may open as tabs.
  • resizeBy affects the outer browser window—not individual elements (use CSS for those).
  • Pair with window.open() features string width and height for initial popup size.

Browser Support

Window.resizeBy() 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.resizeBy()

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
resizeBy() Universal

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

Conclusion

window.resizeBy() adjusts a browser window by relative pixel deltas. It complements resizeTo() and fits popup workflows more often than everyday page layout.

Pass positive values to grow and negative values to shrink, trigger resizes from user actions, and prefer CSS for in-page design. For helper windows, open with window.open() and call popup.resizeBy() on the returned reference.

💡 Best Practices

✅ Do

  • Use resizeBy on popups you opened with window.open()
  • Trigger resizes from button clicks when possible
  • Keep deltas small for predictable adjustments
  • Use negative values to shrink intentionally
  • Learn resizeTo() when you need exact dimensions

❌ Don’t

  • Pass current innerWidth thinking it sets absolute size
  • Resize the user’s main tab without clear consent
  • Use resizeBy for responsive layout by screen width
  • Confuse window resizing with DOM/CSS layout
  • Auto-resize windows on every page load

Key Takeaways

Knowledge Unlocked

Five things to remember about resizeBy()

Your foundation for relative window resizing in JavaScript.

5
Core concepts
02

Relative

From current size.

Delta
🚫 03

Restricted

Main tab blocked.

Policy
🔌 04

Popups

popup.resizeBy

open()
📍 05

vs resizeTo

Exact dimensions.

Pair

❓ Frequently Asked Questions

It changes the size of the current window by a relative amount. The first argument adds pixels to the width; the second adds pixels to the height. Positive values grow the window; negative values shrink it.
resizeBy(deltaWidth, deltaHeight) adjusts from the current size. resizeTo(width, height) sets an exact outer width and height. Use resizeBy for nudging; use resizeTo when you know the target dimensions.
No. Modern browsers restrict programmatic window resizing for security and UX. resizeBy() 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.innerWidth and window.innerHeight before and after if you need to inspect the viewport size.
Yes. resizeBy(-100, -50) shrinks the window by 100px width and 50px height. Browsers may enforce a minimum window size, so very small results can be clamped.
No. Responsive design belongs in CSS and flexible DOM layout. resizeBy() is for rare popup or helper-window workflows—not for adapting content to screen width.
Did you know?

Early web apps paired resizeBy with moveBy to mimic floating tool palettes. Modern sites achieve similar UX with in-page panels and CSS—without fighting browser window restrictions.

Continue to resizeTo()

Learn how to set exact window width and height with the window.resizeTo() method.

resizeTo() 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