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
Fundamentals
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.
Concept
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.
Foundation
📝 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.
Before: 1024×768
After: 1074×798
(values depend on your window; unchanged if resize blocked)
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.
Applications
🚀 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.
Important
📝 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.
Compatibility
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 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
resizeBy()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.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.
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
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about resizeBy()
Your foundation for relative window resizing in JavaScript.
5
Core concepts
📝01
Syntax
resizeBy(dw, dh)
API
↔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.