The fastest way to close a window is Alt+F4 on Windows or Command+W on Mac

Alt+F4 closes the active window on any Windows computer. Press and hold Alt, then tap F4 once, then release both keys. The window disappears when ready. On a Mac, use Command+W instead — hold Command, tap W, release both.

These shortcuts work in almost every program: web browsers, email clients, text editors, file managers, spreadsheets. They close the single window you are looking at without affecting other windows from the same program or other programs running in the background.

If you have unsaved work, most programs will ask you to save before closing. If you want to close the program entirely rather than just one window, use Alt+F4 twice on Windows (once to close the window, once to close the program) or Command+Q on Mac to quit the whole process.

Key Takeaways

  • Alt+F4 on Windows and Command+W on Mac close the active window without closing the entire program.
  • These shortcuts work in nearly all programs and are faster than clicking the X button with a mouse.
  • If you have unsaved changes, the program will prompt you to save before the window closes.
  • Command+Q on Mac or Alt+F4 used twice on Windows will close the entire program, not just one window.

Why keyboard shortcuts are faster than using the mouse

Your hands stay on the keyboard while you work. Reaching for the mouse, moving it to the X button in the corner of the window, and clicking takes longer than pressing two keys at once. Over a day of opening and closing many windows, the time adds up.

Keyboard shortcuts also work the same way in every program. Once you learn Alt+F4 or Command+W, you do not have to hunt for a close button or remember where it is. The muscle memory transfers when ready to the next program you open.

What happens if you close a window by accident

If you close a window with unsaved work, the program catches it. A dialog box appears asking whether you want to save your changes, discard them, or cancel the close action. Click the button that matches what you want — usually "Save" if you want to keep your work, or "Don't Save" if you want to throw it away.

If you close a window and realize when ready that you did not mean to, you can often undo the close by pressing Ctrl+Shift+T on Windows (in web browsers) or Command+Shift+T on Mac. This reopens the last closed tab or window. This works in Chrome, Firefox, Edge, and Safari, though it may not restore your exact scroll position or form entries.

Closing multiple windows at once

If you want to close an entire program and all its windows, use Alt+F4 on Windows or Command+Q on Mac. This closes every window that program has open. Again, if any window has unsaved work, you will see a save dialog.

If you want to close all windows except the one you are looking at, there is no single keyboard shortcut that works across all programs. In web browsers, you can close all other tabs by right-clicking a tab and selecting "Close other tabs," but this requires the mouse. The fastest keyboard-only method is to close each window individually with Alt+F4 or Command+W.

Keyboard shortcuts for managing windows without closing them

Sometimes you want to hide a window or switch between windows instead of closing them. On Windows, Alt+Tab cycles through all open windows and programs. Hold Alt and tap Tab repeatedly to move through them, then release Alt when you reach the one you want.

On Mac, Command+Tab does the same thing. You can also use Command+` (the backtick key, usually in the top left) to cycle through windows within the same program — useful if you have multiple documents open in one process.

To minimize a window without closing it, press Windows key+H on Windows or Command+M on Mac. The window hides but stays open in the background. You can bring it back by clicking its icon in the taskbar (Windows) or dock (Mac), or by using Alt+Tab or Command+Tab to cycle back to it.

When Alt+F4 or Command+W does not work

Some full-screen programs, games, and specialized applications disable these shortcuts. If Alt+F4 or Command+W does not close the window, try clicking the X button in the corner instead. If there is no visible X button, the program may be in full-screen mode — press Escape to exit full-screen, then try the keyboard shortcut again.

If a program is frozen and will not respond to any input, you can force it to close. On Windows, press Ctrl+Alt+Delete, select "Task Manager," find the frozen program in the list, click it, and click "End Task." On Mac, press Command+Option+Escape, select the frozen program, and click "Force Quit."

Frequently Asked Questions

Does Alt+F4 work on all Windows computers?

Yes, Alt+F4 is built into Windows and works on every version from Windows 7 onward. It works in all standard programs. Some games and specialized software may disable it, but the shortcut itself is always available at the system level.

What is the difference between closing a window and minimizing it?

Closing a window shuts it down completely — the program stops running that window. Minimizing hides it from view but keeps it open in the background. You can bring a minimized window back by clicking its taskbar or dock icon. A closed window is gone until you open the program again.

Can I undo closing a window if I did not save my work?

Most programs will ask you to save before closing, so you get a chance to change your mind. If you close without saving and the program does not prompt you, the work is lost. Some programs like Google Docs save automatically, so your work may still exist online even if you close the window.

Why does Command+W on Mac sometimes close the entire program instead of just one window?

If a program has only one window open, Command+W closes that window and the program exits. If the program has multiple windows, Command+W closes only the active window. To close the entire program regardless of how many windows are open, use Command+Q instead.

Is there a keyboard shortcut to close all tabs in a web browser at once?

No single shortcut closes all tabs. You can close the entire browser with Alt+F4 on Windows or Command+Q on Mac, which closes all tabs at once. To close individual tabs, use Ctrl+W on Windows or Command+W on Mac, then repeat for each tab you want to close.