Managing multiple open tabs on Safari can sometimes feel overwhelming, especially when you have too many open ones.
If you’re using an iPhone or iPad, you can close all the tabs simultaneously, which can be a time-saver when you want to clear your browsing history or start fresh.
This article explains how you can close all your Safari tabs quickly, covering both manual and automation methods for iOS 10 and later.
Closing Safari Tabs Manually

For most users, closing tabs manually is the most straightforward method. Here’s how you can do it:
- Open Safari: Launch the Safari browser on your iPhone or iPad.
- View Open Tabs: Tap the tabs icon in the bottom right corner of Safari. This will display all the tabs that are currently open.
- Close Tabs One by One: You can manually swipe each tab to close it. To do this, swipe left on the tab preview, and the tab will close. This method works well if you only have a few tabs open.
- Close All Tabs at Once:
- Tap and hold the “Done” button in the lower-right corner of the screen.
- A menu will pop up asking if you want to close all tabs. Select “Close All [number] Tabs,” and they will be closed immediately.
This method works well for users who prefer a manual approach and don’t mind going through each tab individually.
Using Automation for Closing All Tabs
If you need a more automated approach, especially when testing applications or automating tasks, you can use a script to close all Safari tabs on iOS 11 and later.
This method is beneficial for developers and testers who want to automate the process of closing tabs as part of their testing routines.
The following is an example of how to close all tabs using Java and Appium for automation on iOS 11 or later. Please note that this script will not work on iOS 10 or earlier versions.

Java Code Sample for Automation:
java
CopyEdit
Map<String, Object> params = new HashMap<>();
// Clear previous parameters
params.clear();
params.put(“automation”, “os”);
driver.executeScript(“mobile:browser:open”, params);
// Switch to the native app context
driver.context(“NATIVE_APP”);
// Find the Tabs section
WebElement browserTab = driver.findElementByXPath(“//*[@label=”Tabs”]”);
// Perform a long press action
TouchAction action = new TouchAction(driver);
action.longPress(browserTab).press(browserTab);
action.perform();
// Release the action after pressing
action.longPress(browserTab).release();
action.perform();
// Prepare parameters to find the Close All option
params.clear();
params.put(“content”, “Close All”);
params.put(“timeout”, “30”);
// Execute the search for Close All button
driver.executeScript(“mobile:text:find”, params);
// Switch to the native app context again
driver.context(“NATIVE_APP”);
// Find the Close All button and click it
driver.findElementByXPath(“//XCUIElementTypeButton[contains(@label,’Close All’)]”).click();
// Wait for a while to ensure tabs are closed
Thread.sleep(10000);
This Java code sample uses Appium to close all open tabs in Safari. Below is an explanation of what each part of the script does:
- Clear Parameters: It first clears any previously set parameters to ensure no conflicting data exists.
- Open Browser: The script triggers the opening of Safari.
- Switch to Native App Context: Appium switches the context to the native app to interact with Safari.
- Locate Tabs Section: It finds the tabs section within Safari using the XPath of the browser tab element.
- Long Press to Trigger Close All Option: The script then simulates a long press on the tabs section to open the options.
- Search for “Close All”: It searches for the “Close All” button within the app’s UI elements.
- Click Close All: The script clicks the “Close All” button to close all tabs.
Automation Limitations
While this method is efficient, it has certain limitations:
- It only works with iOS 11 and later versions, meaning it cannot be used on iOS 10 or earlier.
- It does not work on Android devices. The code sample is designed specifically for iOS automation.
Conclusion
Whether you’re clearing tabs for personal use or automating the process for testing purposes, knowing how to close all tabs on your iPhone or iPad quickly can be a big time-saver.
For most users, manually closing tabs through Safari’s interface is the easiest option.
However, for those who need to automate the process, a script with Appium is a powerful tool for closing all tabs in Safari on iOS devices.
Ensure you’re using the correct version of iOS to ensure compatibility with automation scripts.
If you’re using iOS 11 or later, the automation method can make your job much easier, especially if you need to run tests or perform batch tasks.
By following these methods, you can efficiently manage your open tabs in Safari and ensure your device stays organized without unnecessary clutter.