DOM Window.localStorage Property
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.localStorageValue
A Storage object for the page's origin, whose data persists across browser sessions.
Example
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.
Desktop





Tablets & Mobile





