sessionStorage is a key-value storage area that a web page can use through the Web Storage API, scoped to the combination of an origin and a single browser tab. A script on a page calls sessionStorage.setItem() to save a string under a name and sessionStorage.getItem() to read it back, and the browser keeps the data for as long as that tab exists. The defining features are the scope and the lifetime. Two tabs open on the same site have two independent stores. A page reload keeps the data; ending the page session normally discards it. Nothing in the store is ever transmitted to the server automatically, which separates this browser session storage from cookies, and its page-session lifetime distinguishes it from localStorage. Browser restoration can preserve a session, so tab closure is not a secure-erasure guarantee. The name invites confusion with login sessions and session cookies, but sessionStorage is a client-side convenience rather than an automatically managed login session. An application may use it for authentication-related data, but the API itself supplies no authentication.
Page Sessions and Origin Scope
MDN describes the mechanism in terms of a page session. A tab has a page-session context, and documents in that context access the storage associated with their origin. Reloading does not create a fresh empty store. Within the tab, data is further divided by origin, meaning scheme, host and port: a page on one origin cannot read entries written by a page on another, and embedded frames from other origins get their own separate areas. A typical use is a multi-step form that stores the current step and the user's entries so that an accidental reload does not wipe them, or a dashboard that remembers which panel was open in this tab without affecting other tabs.
Values are strings. Storing an object requires serialising it, usually with JSON, and reading it back requires parsing. The API is synchronous, so very large reads and writes can block the page, and browsers impose quotas that vary between implementations. Writes can also fail with a SecurityError when the user's settings forbid the page from persisting data; MDN notes that blocking cookies is commonly interpreted by browsers as an instruction to block storage too, so code should handle the exception rather than assume success.
Reloads, New Tabs and Closing
The sessionStorage lifetime is tied to the tab, not to the page. MDN states that a page session lasts as long as the tab or the browser is open and survives page reloads and restores. Navigating within the same origin in the same tab keeps the data; so does using the back button; so does a browser restoring the tab after a crash or restart, in browsers that implement restore for storage. Ordinary session termination clears the store. Restoration features can retain it, so developers should not rely on closing a tab to revoke access or securely erase secrets.
Opening a link in a new tab behaves differently from what many developers expect. The new tab starts with its own store. There is one special case: when a page is opened with an opener, for example through window.open(), the new tab's sessionStorage is initially a copy of the opener's store. The two remain separate from that moment, and changes in one do not appear in the other. Code that relies on this copy should be aware that it is a snapshot, not a shared channel, and that techniques which sever the opener relationship prevent the copy altogether.
sessionStorage vs Cookies and localStorage
The three mechanisms are often grouped together because all hold small amounts of client-side state, but they differ on every axis that matters for design.
| Property | sessionStorage | localStorage | Cookies |
|---|---|---|---|
| Scope | Origin plus tab | Origin, shared across tabs | Domain and path rules |
| Lifetime | Page-session lifetime; restoration can preserve it | Persists, subject to clearing and browser policy | Session or explicit expiry |
| Sent to server | Not automatically | Not automatically | On eligible requests, subject to browser policy |
| Readable by page script | Yes | Yes | Unless HttpOnly |
| Typical size | Megabytes, browser-dependent | Megabytes, browser-dependent | About 4 KB each |
sessionStorage vs localStorage comes down to tab scope and persistence. MDN summarises the distinction as localStorage being partitioned by origin only while sessionStorage is partitioned by origin and tab, with sessionStorage data kept only for the duration of the page session. localStorage is right for preferences that should still be there next week; sessionStorage is right for state that belongs to this tab's current task. Private browsing usually makes localStorage temporary too, but does not turn its cross-tab scope into sessionStorage scope. Exact restoration and clearing behaviour depends on the browser.
The comparison with session cookies is where the name misleads most. A session cookie has neither Max-Age nor Expires. It can be available across tabs under its cookie scope, and the browser sends it on eligible requests. Session restoration may preserve such cookies as well. sessionStorage is per tab and is not transmitted automatically. A cookie-based login can therefore work across tabs without copying a sessionStorage value. Either mechanism may hold a value that an application associates with server-side state; neither is itself that server-side record.
Partitioning and Embedded Contexts
Modern browsers further isolate storage by the top-level site. Firefox's state partitioning documentation lists sessionStorage among the APIs double-keyed by the origin of the resource and the top-level site, and Chrome's storage partitioning does the same, so a third-party frame embedded on two different sites sees two different stores even within what would otherwise be one tab session. This generally leaves ordinary first-party use unchanged but matters for widgets and embedded tools that previously assumed shared state across embedding sites.
Uses and Limitations
sessionStorage suits transient interface state: wizard progress, scroll positions, draft text that should survive a reload, filters applied in this tab, and flags that prevent a one-time notice from reappearing during the current visit. It avoids the request overhead of cookies and the cross-tab leakage of localStorage.
It is not a secure store. Any script running in the page, including an injected one, can read every entry for that origin, so authentication tokens and personal data do not belong there without a considered threat model. It is also not reliable storage: users can clear it, browsers can refuse writes, and session termination can remove it without an application-specific save step. Server-side state remains the source of truth for anything that must persist or be trusted, and sessionStorage should hold only what the page can afford to lose.