localStorage
A browser store of up to about 5 MB per site that scripts read at any time and that survives restarts.
In one line
Can keep up to about 5 MB of text notes per site, until cleared
A browser store of up to about 5 MB per site that scripts read at any time and that survives restarts.
Holds settings, drafts, and very often a tracker's visitor ID that is re-created if the cookie is deleted. It is not sent to servers on its own, but every script on the page can read it. A common 'respawn' source for IDs.
What it can and can't do
What the user does: Nothing. It happens as you use the site or change settings.
It can
- Remember settings, drafts and sign in tokens
- Keep them after you restart the browser
- Use them again on every visit
It cannot
- Let other sites see them
- Hold large files
- Keep them after you clear site data or close a private window
- Keep them in Safari after 7 days of use without a visit
How it differs between platforms: Safari may delete it after 7 days of use without a visit. Chrome and Firefox do not.
Browser support
| Browser | Status | First version | Released | Note |
|---|---|---|---|---|
| Chrome | Supported | 4 | 2010-01-25 | None |
| Edge | Supported | 12 | 2015-07-29 | None |
| Firefox | Supported | 3.5 | 2009-06-30 | None |
| Safari | Supported | 4 | 2009-06-08 | None |
| Safari on iPhone | Supported | 3.2 | 2010-04-03 | None |
| Chrome on Android | Supported | 18 | 2012-06-27 | None |
| Samsung Internet | Supported | 1.0 | 2013-04-27 | None |
How a site asks for it
| API | window.localStorage.setItem(k, v) |
| Browser compat keys | api.Window.localStorage |
| How access is granted | none |
| What the user sees | None |
| Needs a secure context (HTTPS) | No |
| Needs a user gesture | No |
| How long it lasts | Until cleared by user or evicted. Safari deletes script written storage after 7 days of Safari use without a user visit |
| How to take it back | Clear site data, browser privacy settings |
| Inside an iframe | Not listed |
Data you get
What comes back: Key value strings
Shape: string
How often: any time
| Field | Type | Unit | Range | Precision |
|---|---|---|---|---|
quota | integer | MiB | about 5 per origin | approximate |
Technical limits
- About 5 MiB per origin in Chrome, Firefox and Safari
- Synchronous API blocks the main thread
- Not shared across origins or (3P) partitions
- No expiry set by the API
- Not available in workers
The story
What it is
A store of up to about 5 MB per site that scripts can read any time and that survives restarts.
For you
You never see it. It is why a site remembers your dark mode, your last search or your game score the next time you come back.
For makers
It is the easiest way to keep small settings, so it is everywhere. It is also a place where trackers store IDs, because it survives restarts and any script on the page can read it.
Where you see it
| Type | Example | Apps |
|---|---|---|
| games | A word game or puzzle keeps your streak and best score here. | Wordle, 2048 |
| productivity | A to do list app remembers your tasks without needing an account. | None named |
| shopping | A store remembers the items you recently viewed. | None named |
| social | A social site remembers a draft post that you did not send. | None named |
| ads | A tracking script stores a visitor ID and your last ad click here. | None named |
| analytics | A site analytics script keeps a session ID here to link visits together. | Google Analytics |
| education | A learning site remembers where you stopped in a lesson. | None named |
Risks
- Hidden trackers
- Readable by any script
What the platform says
- MDN: Web Storage API. Documents how sites save small amounts of data in the browser for later visits.
Good uses and abuse
Legitimate uses
- User settings, offline drafts, feature flags
Known abuse
- Respawning tracking IDs after cookie deletion
Scores
| Score | Value | Meaning |
|---|---|---|
| Sensitivity | 3 of 5 | How revealing the data is |
| Utility | 5 of 5 | How useful it is to honest apps |
| Friction | 0 of 5 | How much the user has to do |
| Fingerprint bits | 0 | Rough identifying entropy, when known |
History
- 2020-03, Safari 13.1: ITP 7 day cap on script writable storage applied to localStorage
- 2022-07, Firefox 103: Total Cookie Protection partitions it for all users
- 2023-07, Chrome 115: Third party localStorage partitioned by top level site
Related capabilities
Related
- sessionStorage. Can keep up to about 5 MB of notes for this tab until you close it
- IndexedDB. Can keep gigabytes of organized data for its own site in your browser
- Safari 7 day script storage deletion. Can't keep script saved data in Safari after 7 days of use without a visit
Sources
How well checked: Checked against real behavior.