Favorites

DOM Window.localStorage Property

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
Window.localStorage
DOM Window PropertyThis property is supported by all modern browsers.
Updated 28th November 2026

The localStorage property gives access to storage that keeps string data in the browser with no expiry, so it survives page reloads and restarts.

Description

The localStorage property returns a Storage object for the site's origin. Data saved in it has no expiry: it stays until it is deleted by your code or the user clears their browser data. It's shared by all tabs on the same origin, and the storage event lets other tabs know when it changes.

Only strings are stored, so convert objects with JSON.stringify(). Access can throw in some privacy modes or sandboxed frames, so wrap it in try...catch. Don't store secrets in it, since any script on the page can read it.

Each origin gets its own storage, so http:// and https:// versions of a site, or different subdomains, don't share data. Reads and writes are synchronous, so storing or parsing large values can briefly freeze the page; keep stored values small.

Syntax

localStorage
window.localStorage

Value

A Storage object for the page's origin, whose data persists across browser sessions.

Example

try {
  const visits = Number(localStorage.getItem('visits') || 0) + 1;
  localStorage.setItem('visits', visits);
  console.log('You have run this example', visits, 'time(s)');
} catch (e) {
  console.log('localStorage is not available here');
}

Browser Support

The following information will show you the current browser support for the Window.localStorage property. Hover over a browser icon to see the version that first introduced support for this property.

This property is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee