Cookies and localstorage are both ways for websites to store small amounts of data in your browser, but they serve very different purposes and behave quite differently.
Here’s a clear comparison:
| Feature | Cookies | LocalStorage |
|---|---|---|
| Purpose | Mainly for server-client communication (sessions, tracking, preferences) | Client-side only data storage (user preferences, saved projects, settings) |
| Sent with requests | Yes — automatically sent with every HTTP request to the same domain | No — never sent to the server |
| Storage limit | About 4 KB per cookie | About 5–10 MB per origin (much larger) |
| Expiration | Can expire (session cookies or set expiration date) | Permanent until manually deleted |
| Accessibility | Can be set to HttpOnly (inaccessible to JavaScript) | Always accessible via JavaScript |
| Security | Can be more secure with HttpOnly and Secure flags | More exposed to XSS attacks |
| Data type | Only strings | Strings (but you can JSON.stringify objects) |
| Use case example | Login session, CSRF tokens, analytics tracking | Saving woodworking project dimensions, user theme preference, or a list of favorite tools |
Quick woodworking-related examples
- Cookie: A site might use a cookie to remember you’re logged into the WoodCentral forum so you don’t have to log in every time you visit.
- LocalStorage: The site could save your preferred board-foot calculator settings or the last few lumber dimensions you entered so they’re still there when you come back next week.
Rule of thumb:
- Use cookies when the server needs to know the information.
- Use localStorage when only the browser needs to remember something and you want more storage space.



