Comparison
Cookies vs local storage
Quick verdict
Use cookies for auth and server-needed state. Use local storage for client-only preferences and larger UI state. Neither is a secret vault.
Side-by-side
| Dimension | Cookies | Local storage |
|---|---|---|
| Sent to server | Yes, for matching domain/path rules | No, unless your code reads and sends it |
| Typical size | Small (about 4KB per cookie) | Larger (often around 5MB+ per origin) |
| Common uses | Sessions, consent, personalization, ads | Drafts, theme settings, cached UI data |
| Expiry | Can be session or dated | Persists until cleared by code or user |
Choose Cookies when
- The server must recognize the user on each request
- You need standard cookie security attributes
- You are implementing login sessions
Choose Local storage when
- Data is only needed in the browser
- You need more room than cookies allow
- You want to avoid attaching data to every request
Common questions
Is local storage more private than cookies?
It is not automatically sent with requests, which changes the threat model, but scripts on the page can still read it. It is not encryption.
Keep reading
- What are cookies on websites?
Website cookies are small pieces of data a site stores in your browser so it can remember information between visits or requests. They can keep you logged in, save preferences, or help analytics and advertising systems recognize activity.
- What is a VPN?
A VPN (virtual private network) encrypts your internet traffic and sends it through a remote server before it reaches the wider web. That can protect data on untrusted networks and change the apparent network location of your connection.
- What is phishing?
Phishing is a social-engineering scam where attackers impersonate trusted people or brands to trick you into sharing secrets, clicking malicious links, or approving harmful actions.