Session storage is part of the Web Storage API. It stores string key-value pairs in the browser, scoped to the origin and to a single browsing tab. Data survives page reloads in that tab but is discarded when the tab or window is closed.
Why it matters
It suits temporary state that should not leak between tabs: a multi-step form's progress, a scroll position, a wizard step or a one-time banner dismissal. Two tabs on the same site get separate session storage, which differs from local storage, where all tabs share the data. Unlike cookies, session storage is never sent to the server automatically, so it adds no request overhead.
Example
sessionStorage.setItem("step", "2");
const step = sessionStorage.getItem("step"); // "2"
sessionStorage.setItem("cart", JSON.stringify({ items: 3 }));
const cart = JSON.parse(sessionStorage.getItem("cart"));
sessionStorage.removeItem("step");
Values are always strings, so objects need JSON.stringify and JSON.parse.
Common mistakes
- Storing tokens or sensitive data; any script on the page, including injected code, can read it.
- Expecting data to be shared between tabs or to survive closing the browser.
- Assuming it is available: private modes or blocked storage can throw errors, so wrap access in
try/catch. - Storing large data; the quota is only a few megabytes.
Related
Get notified when this term updates
Plus occasional practical tips on uptime and monitoring, nothing else. Unsubscribe anytime.
This page is general information written by our editorial team and updated when documentation changes. Servers and providers differ, so test changes safely first. See our editorial policy and disclaimer.