---
id: api/commands/clearlocalstorage
title: clearLocalStorage | Cypress Documentation
description: Clear data in localStorage for current domain and subdomain in Cypress.
section: api
source_path: docs/api/commands/clearlocalstorage.mdx
version: 998ed2fab5510b3f672383c6cb23238bf481edb8
updated_at: '2026-05-24T20:45:33.543Z'
---
# clearLocalStorage

Clear data in localStorage for current domain and subdomain.

Cypress automatically clears all local storage _before_ each test to prevent state from being shared across tests when [test isolation](/llm/markdown/app/core-concepts/writing-and-organizing-tests.md#Test-Isolation) is enabled. You shouldn't need to use this command unless you're using it to clear localStorage inside a single test or test isolation is disabled.

## Syntax

```
cy.clearLocalStorage()cy.clearLocalStorage(key)cy.clearLocalStorage(options)cy.clearLocalStorage(keys, options)
```

### Usage

**Correct Usage**

```
cy.clearLocalStorage() // clear all local storage
```

### Arguments

**keys _(String, RegExp)_**

Specify key to be cleared in localStorage.

**options _(Object)_**

Pass in an options object to change the default behavior of `cy.clearLocalStorage()`.

| Option | Default | Description |
| --- | --- | --- |
| `log` | `true` | Displays the command in the [Command log](/llm/markdown/app/core-concepts/open-mode.md#Command-Log) |

### Yields [Learn about subject management](/llm/markdown/app/core-concepts/introduction-to-cypress.md#Subject-Management)

*   `cy.clearLocalStorage()` yields the localStorage for the current domain.

## Examples

### No Args

#### Clear all localStorage

```
cy.clearLocalStorage()
```

### Specific Key

#### Clear localStorage with the key 'appName'

```
cy.clearLocalStorage('appName')
```

#### Clear all localStorage matching `/app-/` RegExp

```
cy.clearLocalStorage(/app-/)
```

## Rules

### Requirements [Learn about chaining commands](/llm/markdown/app/core-concepts/introduction-to-cypress.md#Chains-of-Commands)

*   `cy.clearLocalStorage()` requires being chained off of `cy`.

### Assertions [Learn about assertions](/llm/markdown/app/core-concepts/introduction-to-cypress.md#Assertions)

*   `cy.clearLocalStorage()` will only run assertions you have chained once, and will not [retry](/llm/markdown/app/core-concepts/retry-ability.md).

### Timeouts [Learn about timeouts](/llm/markdown/app/core-concepts/introduction-to-cypress.md#Timeouts)

*   `cy.clearLocalStorage()` cannot time out.

## Command Log

**_Clear all localStorage_**

```
cy.clearLocalStorage(/prop1|2/).then((ls) => {  expect(ls.getItem('prop1')).to.be.null  expect(ls.getItem('prop2')).to.be.null  expect(ls.getItem('prop3')).to.eq('magenta')})
```

The commands above will display in the Command Log as:

When clicking on `clearLocalStorage` within the command log, the console outputs the following:

## See also

*   [`cy.clearCookies()`](/llm/markdown/api/commands/clearcookies.md)
