localStorage and sessionStorage

Small key-value storage in the browser; localStorage survives restarts, sessionStorage ends with the tab.

Also called: sessionStorage, Web Storage, IndexedDB

Source
General
Language
JavaScript

In plain English

Only strings, about 5 MB, readable by any script on the page, so never store secrets or tokens there.

Example

The PC builder keeps your chosen parts in localStorage, so they survive a reload.

In code

localStorage.setItem('build', JSON.stringify(parts));
const parts = JSON.parse(localStorage.getItem('build') ?? '[]');

Learn more

Related terms

Added 2026-11-30 · Last reviewed 2026-11-30