What is session storage and how is it different from local storage?

Home / Everything About / Everything About Websites / What is session storage and how is it different from local storage?

Session storage saves data in the browser only for as long as a tab is open. Learn how it works, how it differs from local storage, and what websites use it for.

What if a website could remember just enough to make your visit smooth, without holding onto anything after you leave? No leftover data, no stored preferences, nothing that lingers. Just the right information for the right moment, and then it is gone. That is the idea behind session storage, and it is more useful than it might first sound.

If you have already read the chapter on local storage, you know that it keeps data alive even after the browser closes. Session storage takes the opposite approach. It is designed to be temporary, and that is not a limitation. It is a deliberate feature.

What is session storage?

Session storage is a type of browser storage that saves data for the duration of a browser tab's session. As long as the tab stays open, the data is available. The moment the visitor closes that tab, session storage is automatically cleared. Open the same website in a new tab and session storage starts fresh with nothing in it.

Like local storage, session storage works as a key-value store. Websites write data using a label and a value, and retrieve it by looking up the label. The difference is purely in how long the data lasts. Local storage persists indefinitely. Session storage lives and dies with the tab.

How is session storage different from local storage?

The key difference is persistence. Local storage data stays in the browser until it is manually deleted. Session storage data disappears the moment the tab closes. This makes them suited for different situations.

Session storage is also tab-specific. If a visitor has the same website open in two different tabs, each tab has its own separate session storage. They do not share data between them. Local storage, on the other hand, is shared across all tabs from the same website on the same browser.

What do websites use session storage for?

Tracking progress within a session

Multi-step forms and checkout flows often use session storage to hold progress as a visitor moves from one step to the next. If they navigate back to a previous step, their answers are still there. Once the session ends, that temporary data is gone, which is exactly what you want for something like a checkout process.

Temporary UI state

Whether a sidebar is open, which tab is currently selected, or how far a visitor has scrolled in a long list — these are all temporary states that make sense to hold during a visit but have no value once the visitor leaves. Session storage handles this cleanly.

Keeping sensitive context short-lived

For anything that relates to a user's current context during a visit, session storage is the safer choice over local storage because the data automatically cleans itself up. There is no risk of sensitive context lingering in the browser after the visit ends.

When to use session storage versus local storage

The choice comes down to one question: does this data need to survive past the current tab session? If yes, local storage is the right tool. If the data is only relevant during the current visit and should not carry over, session storage is the better fit.

For sensitive data, neither is appropriate. Passwords, payment details, and personal information should always be handled server-side with proper SSL encryption, never stored in the browser. For a full picture of all browser storage options and how they compare, read types of browser storage.

Frequently asked questions

Does session storage clear when the browser closes, or just the tab?

Can two tabs on the same website share session storage?

Is session storage more secure than local storage?

What happens to session storage if a visitor refreshes the page?

How much data can session storage hold?

Do I need to configure session storage on my website?