localStorage and sessionStorageBaseline · Widely available
The localStorage and sessionStorage APIs store data as key-value pairs. While localStorage persists across sessions, sessionStorage data is discarded when the page is closed.
Supported in all major browsers for at least 30 months — safe to use without fallbacks. Baseline since Jul 29, 2015. Widely available since Jan 29, 2018.
Browser support
DesktopChrome
1–3Not supported
4+Supportedsince Jan 25, 2010
Current: 155Edge
12+Supportedsince Jul 29, 2015
Current: 154Firefox
1–3Not supported
3.5+Supportedsince Jun 30, 2009
Current: 157Safari
1–3.1Not supported
4+Supportedsince Jun 8, 2009
Current: 27MobileChrome Android
18+Supportedsince Jun 27, 2012
Current: 155Firefox Android
4–5Not supported
6+Supportedsince Aug 16, 2011
Current: 157Safari iOS
1–3Not supported
3.2+Supportedsince Apr 3, 2010
Current: 27How to use
This feature is Baseline widely available — use it freely, no fallback needed.
Example
JS
try {
localStorage.setItem("theme", "dark");
const theme = localStorage.getItem("theme") ?? "light";
} catch {
// storage can be disabled (private mode, blocked cookies)
}Feature detection
JS · check before using
if ("Window" in globalThis && "localStorage" in Window.prototype) {
// Window.localStorage is available
}Documentation (MDN)
Specification
Usage share
Sub-features
Support for each part of the feature (17). The overall table above shows when the whole feature works.
| Sub-feature | Chrome | Edge | Firefox | Safari | Chrome Android | Firefox Android | Safari iOS |
|---|---|---|---|---|---|---|---|
| Storage | 4 | 12 | 3.5 | 4 | 18 | 6 | 3.2 |
| Storage.clear | 4 | 12 | 3.5 | 4 | 18 | 6 | 3.2 |
| Storage.getItem | 4 | 12 | 3.5 | 4 | 18 | 6 | 3.2 |
| Storage.key | 4 | 12 | 3.5 | 4 | 18 | 6 | 3.2 |
| Storage.length | 4 | 12 | 3.5 | 4 | 18 | 6 | 3.2 |
| Storage.removeItem | 4 | 12 | 3.5 | 4 | 18 | 6 | 3.2 |
| Storage.setItem | 4 | 12 | 3.5 | 4 | 18 | 6 | 3.2 |
| StorageEvent | 1 | 12 | 13 | 4 | 18 | 14 | 3 |
| StorageEvent.StorageEvent | 17 | 17 | 13 | 6 | 18 | 14 | 6 |
| StorageEvent.key | 1 | 12 | 13 | 4 | 18 | 14 | 3 |
| StorageEvent.newValue | 1 | 12 | 13 | 4 | 18 | 14 | 3 |
| StorageEvent.oldValue | 1 | 12 | 13 | 4 | 18 | 14 | 3 |
| StorageEvent.storageArea | 3 | 12 | 13 | 4 | 18 | 14 | 3 |
| StorageEvent.url | 6 | 12 | 13 | 5 | 18 | 14 | 5 |
| Window.localStorage | 4 | 12 | 3.5 | 4 | 18 | 4 | 3.2 |
| Window.sessionStorage | 4 | 12 | 2 | 4 | 18 | 4 | 3.2 |
| Window.storage_event | 1 | 15 | 45 | 4 | 18 | 45 | 4 |