शब्दकोश · वेब डेवलपमेंट

Session Storage

Session storage is a browser API that stores key-value strings for the lifetime of a single tab, clearing them when that tab or window closes.

अपडेट: अक्टूबर 6, 2026

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.

Get notified when this term updates

Plus occasional practical tips on uptime and monitoring, nothing else. Unsubscribe anytime.

यह पेज सामान्य जानकारी है, जिसे हमारी संपादकीय टीम ने लिखा है और दस्तावेज़ीकरण बदलने पर अपडेट किया जाता है। सर्वर और प्रदाता अलग-अलग होते हैं, इसलिए बदलाव पहले सुरक्षित तरीके से जाँचें। देखें: संपादकीय नीति और अस्वीकरण.