WWW FAQs: How do I resize the web browser window?

2005-08-18: Normally it's not a good idea to resize the web browser window. The user typically has set it to the size they prefer. It's easy to open a new window of any size in response to a click on a link or a button, and users typically prefer this to a sudden change in the size of their "main" web browsing window.

If your circumstances call for it, though, you can resize the window very easily by inserting this code into the <head> element of your page:

window.resizeTo(width, height);

Of course, you should replace width and height with the width and height you want, in pixels.

However, bear in mind that you are specifying the width and height of the entire browser window, including the menu bar, the button bar, various toolbars and so forth. And you can't know precisely how much of that space will be available to your layout. However, you can adjust the size of the browser window to fully accommodate your layout. See the article How do I make the window size match my layout? for a complete solution to that problem.

Legal Note: yes, you may use sample HTML, Javascript, PHP and other code presented above in your own projects. You may not reproduce large portions of the text of the article without our express permission.

Got a LiveJournal account? Keep up with the latest articles in this FAQ by adding our syndicated feed to your friends list!