Working with tabs in Safari can be convenient and keep you organized. If you accidentally close a tab you're using, you don't need to open another new tab and enter the URL again.
Safari remembers the tab you just closed, and with a trip to a Safari menu or a quick keyboard command, you can reopen the lost tab.
Instructions in this article apply to Safari 10 and later.
How to Undo a Closed Tab in Safari
You can open your lost tab using four methods. The first is to either select Undo Close Tab from the Edit menu, or press Command+Z on your keyboard.
You can restore multiple tabs you've closed by using the command repeatedly.
Another way to reopen a page you've closed is to click and hold the plus sign at the far right of the Tabs bar. Usually, you click this once to open a new tab, but holding opens a menu with a list of ones you've recently closed. Select the one you want to reopen.
The third way is to select Reopen Last Closed Tab under the History menu or press Shift+Command+T on your keyboard.
Finally, you can find a list of tabs you've recently closed under the History menu. Mouse over Recently Closed to see a list of pages you can reopen, and then click the one you want to restore.
Restoring Closed Windows
If you close a Safari window, you can reopen it just as you can reopen a closed tab, but the command is under a different menu. Select Reopen Last Closed Window under the History menu, or press Shift+Command+T on your keyboard.
The Reopen Last Closed Window and Reopen Last Closed Tab commands share the same spot in the History menu and keyboard shortcut. Which you see depends on which you closed most recently.
Reopen Safari Windows From Last Session
Besides being able to reopen closed Safari windows and tabs, you can also open all Safari windows that were open the last time you quit Safari.
Safari, like all the Apple apps, can make use of OS X's Resume feature, which was introduced with OS X Lion. Resume saves the state of all the open windows of an app, in this case, any Safari window you have open. The idea is that the next time you launch Safari, you can resume right where you left off.
From the History menu, select Reopen All Windows From Last Session.