Skip to content

sessionStorage

sessionStorage stores data for the duration of a page session. Data is cleared when the tab or browser is closed.

// Same API as localStorage, but cleared on tab close
sessionStorage.setItem('tabState', JSON.stringify({ scrollPosition: 150 }));
const state = JSON.parse(sessionStorage.getItem('tabState'));
FeaturelocalStoragesessionStorage
PersistenceUntil explicitly clearedUntil tab closes
ScopeAll tabs of same originCurrent tab only
Storage limit~5-10MB~5-10MB
Sent to serverNoNo
  • Temporary form state (user refreshes → data preserved)
  • Tab-specific preferences
  • Multi-step wizard progress
  • Shopping cart for the current session
  • Same API as localStorage
  • Data persists only for the current browser tab
  • Cleared when tab/window is closed
  • Use for temporary, tab-specific data