Updated 2026-11-17

Cookies vs local storage

Filed under Internet literacy

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

DimensionCookiesLocal storage
Sent to serverYes, for matching domain/path rulesNo, unless your code reads and sends it
Typical sizeSmall (about 4KB per cookie)Larger (often around 5MB+ per origin)
Common usesSessions, consent, personalization, adsDrafts, theme settings, cached UI data
ExpiryCan be session or datedPersists 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