The sessionStorage property allows you to access a session Storage object for the current origin. sessionStorage is similar to localStorage; the only difference is while data stored in localStorage has no expiration time, data stored in sessionStorage gets cleared when the page session ends. A page session lasts for as long as the browser is open and survives over page reloads and restores.

Opening a page in a new tab or window causes a new session to be initiated with the value of the top-level browsing context, which differs from how session cookies work. Opening multiple tabs or Windows on the same URL creates sessionStorage for each tab or Window. Closing a tab or Window ends the session and the objects in sessionStorage are cleared as soon as the tab or Window is closed.

It should be noted that data stored in either sessionStorage or localStorage is specific to the protocol of the page. In other words, will have separate local storage and session storage from


// Save data to sessionStorage
sessionStorage.setItem('key', 'value');

// Get saved data from sessionStorage
let data = sessionStorage.getItem('key');

// Remove saved data from sessionStorage

// Remove all saved data from sessionStorage


A Storage object.


The following snippet accesses the current domain's session Storage object and adds a data item to it using Storage.setItem().

sessionStorage.setItem('myCat', 'Tom');

The following example autosaves the contents of a text field, and if the browser is accidentally refreshed, restores the text field content so that no writing is lost.

// Get the text field that we're going to track
let field = document.getElementById("field");
// See if we have an autosave value
// (this will only happen if the page is accidentally refreshed)
if (sessionStorage.getItem("autosave")) {
  // Restore the contents of the text field
  field.value = sessionStorage.getItem("autosave");
// Listen for changes in the text field
field.addEventListener("change", function() {
  // And save the results into the session storage object
  sessionStorage.setItem("autosave", field.value);

Note: Please refer to the Using the Web Storage API article for a full example.


Specification Status Comment
HTML Living Standard
The definition of 'sessionStorage' in that specification.
Living Standard

Browser compatibility

Update compatibility data on GitHub
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
sessionStorageChrome Full support 5Edge Full support 12Firefox Full support 2IE Full support 8Opera Full support 10.5Safari Full support 4WebView Android Full support YesChrome Android Full support YesFirefox Android Full support YesOpera Android Full support 11Safari iOS Full support 3.2Samsung Internet Android Full support Yes


Full support  
Full support

See also