DOM Storage Interface
The Storage interface gives access to localStorage and sessionStorage, which store string key-value pairs in the browser.
Description
The Storage interface provides access to a domain's local or session storage, through window.localStorage and window.sessionStorage. Data is stored as string key-value pairs; use JSON.stringify() and JSON.parse() for objects.
Its methods are setItem(), getItem(), removeItem(), clear() and key(), plus a length property. Storage is synchronous and limited to a few megabytes per site, so it suits small settings rather than large data, for which IndexedDB is better. Never store sensitive information such as passwords or tokens in it.
Data in localStorage is only available to pages from the same origin: the same protocol, host and port. Browsers may clear storage when space runs low or in private browsing, so treat it as a cache that can disappear, not as permanent storage. When storage changes in one tab, other tabs from the same origin receive a storage event on window, which can keep them in sync.
Methods
| Name | Description |
|---|---|
Storage.getItem() | The getItem() method reads the value stored under a key in localStorage or sessionStorage, returning null if there is none. |
Storage.removeItem() | The removeItem() method deletes a key and its value from localStorage or sessionStorage. |
Storage.setItem() | The setItem() method saves a value under a key in localStorage or sessionStorage, replacing any existing value. |
Example
Browser Support
The following information will show you the current browser support for the Storage interface. Hover over a browser icon to see the version that first introduced support for this interface.
Desktop





Tablets & Mobile





