Home / Learn HTML / HTML Web Storage
HTML Web Storage
Save small data inside the visitor browser. It stays even after closing the tab.
localStorage stays for ever. sessionStorage is erased when the tab closes.Definition
Web Storage lets JavaScript keep small amounts of data in the visitor's browser. localStorage stays until deleted; sessionStorage is cleared when the tab closes. Both store text as key and value pairs, about 5 MB per site, and are never sent to the server automatically.
Theory in plain words
What it is
Web Storage lets a page save small data in the browser: localStorage stays, sessionStorage ends with the tab.
Why we use it
It remembers settings such as theme or a draft without a server or cookies.
How it works
Data is saved as text keys and values for one site. Scripts read and write it. It is not safe for secrets.
Where it is used
- Dark mode setting
- Shopping cart draft
- Saved form data
Some browsers block storage inside previews. If it does not remember, try on your own page.
Quick quiz
1. Which storage stays after closing the browser?
localStorage persists.
2. Storage keeps values as
Use JSON.stringify for objects.
3. Should you store passwords in it?
Anyone on that browser can read it.
Common questions
Which storage stays after closing the browser?
localStorage. localStorage persists.
Should you store passwords in it?
Never. Anyone on that browser can read it.