Favorites

DOM Storage Interface

☕
Enjoying this site?

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

Buy us a coffee
Storage
DOM InterfaceThis interface is supported by all modern browsers.
Updated 28th November 2026

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

NameDescription
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

try {
  localStorage.setItem('theme', 'dark');
  localStorage.setItem('prefs', JSON.stringify({ size: 'l' }));
  console.log(localStorage.getItem('theme'));
  console.log(JSON.parse(localStorage.getItem('prefs')).size);
  console.log(localStorage.length);
} catch (e) {
  console.log('Storage is not available here:', e.name);
}

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.

This interface 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