HTMLMedium
Compare localStorage, sessionStorage and cookies
By FrontendPro Editorial Team Updated 8/7/2026
#html#storage#browser
Answer
| Size | Lifetime | Sent with requests | |
|---|---|---|---|
localStorage | ~5–10MB | Until cleared | No |
sessionStorage | ~5MB | Until the tab closes | No |
| Cookie | ~4KB | Per Expires/Max-Age | Yes (every same-domain request) |
- Session tokens belong in an
HttpOnly+Secure+SameSitecookie so JS can't read them (XSS token theft). - The Storage API is synchronous and string-only → you
JSON.stringifyyourself, and large writes block the main thread.
