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

Session storage saves data in the browser for the duration of a tab session. Learn how it works, how it compares to local storage, and what websites use it for.

Draft

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?

Session storage clears when the specific tab is closed. If a visitor has multiple tabs open and closes one, only that tab's session storage is cleared. The other tabs keep their own session storage. If the entire browser is closed, all session storage across all tabs is wiped because all active sessions end at that point.

Can two tabs on the same website share session storage?

No. Session storage is isolated per tab. If the same website is open in two separate tabs, each tab has its own session storage that the other tab cannot read or write to. This is different from local storage, which is shared across all tabs from the same website on the same browser.

Is session storage more secure than local storage?

It is slightly better for sensitive context because data clears automatically when the tab closes. But it is still accessible to any script running on the page, which means it is not suitable for passwords, personal details, or payment information. The automatic cleanup reduces the window of exposure, but the same basic security rules apply. Sensitive data belongs on the server, not in the browser.

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

Refreshing the page does not clear session storage. The data persists through page reloads as long as the tab remains open. This makes session storage useful for holding state across refreshes within the same visit, like keeping a form partially filled in, without that data carrying over after the visitor leaves.

How much data can session storage hold?

Session storage has roughly the same capacity as local storage, around 5 to 10 megabytes per tab depending on the browser. That is more than enough for temporary UI states and in-progress form data. For larger datasets or files, IndexedDB is better suited.

Do I need to configure session storage on my website?

Not if you are using a website builder. Session storage is used internally by the platform for things like managing form state and in-session preferences. It runs in the background without any setup on your part. With WEMASY's website builder, the platform handles all browser storage decisions automatically so your visitors get a smooth experience without any configuration needed.

Put it to work
on your own website.

Start free with WEMASY and build your site in a few minutes.