How the web works · API

localStorage and sessionStorage

Simple built-in browser storage where a site can save small pieces of text, such as a theme choice or a half-written draft, that survive a page reload.

In the browser · Free · updated

How it works

Both store text keys and values for one site (strictly, one origin), through calls such as localStorage.setItem('theme', 'dark'). localStorage keeps data until the site or the user clears it; sessionStorage lasts only as long as the tab. Browsers allow about 5 MB per site, and anything that is not text, such as an object, has to be turned into a JSON string first.

The API is synchronous, so large reads and writes can briefly freeze the page, and it is not available in service workers; IndexedDB suits larger or structured data. Any script on the page can read it, so a cross-site scripting (XSS) bug exposes everything inside, which is why sign-in tokens are safer in an HttpOnly cookie. Nothing stored here is sent to the server automatically.

localStorage and sessionStorage pricing

Free

Free; part of the browser.

Approximate, checked September 2026.What the other tools cost

localStorage and sessionStorage vs the alternatives

More in How the web works

In the browser

All 20 How the web works terms

Crafted in the dark. Shipped to the world.

Tell us what you are building. You get a private project space with a proposal and a line-by-line quote within a day.