What is the maximum size of a cookie, and how many can be stored in a browser for each web site?

No more than 50 cookies per domain, with a maximum of 4 KB per cookie (or even 4 KB in total, see Iain’s answer). On IE 6 it used to be 20 cookies per domain.

Generally it’s recommended to preserve state on the server, and use cookies only for session tracking. They’re sent along with every request, so they form an unnecessary overhead if the purpose is to keep session state around.

If you do want to keep state on the client, and you can use JavaScript to do it, there are options. Use the assorted storage API’s directly or find a wrapper library that abstracts away the details.

Client-side storage options:

  • localStorage: Firefox 2+, Chrome 4+, Safari 4+, Internet Explorer 8+. 5 MB per domain without user confirmation (but be aware that it is stored as UTF-16 so you may use two bytes per character).
  • IndexedDB: Firefox 4+, Chrome 11+, Safari 10+, Internet Explorer 10+. 5 MB per domain without user confirmation, much more after confirmation (highly browser specific, check your browser for details).

Deprecated storage options:

  • Flash 8 persistent storage: any browser with Flash 8+. 100 KB, more with user permission. Deprecated because Flash itself is deprecated.
  • userData: Internet Explorer 5.5+. 64 KB per domain in the restricted zone, 128 KB per domain in the internet zone. Replaced by localStorage.
  • Web SQL: Chrome & Safari only, it will never make it to other browsers because it was not possible to standardize it.

So, generally for client-side storage it depends on the use case:

  • For session id tracking or for a few KB, use cookies.
  • Up to 2 MB, localstorage delivers a solution across all common browsers.
  • 2 MB and up, use IndexedDB (look for a good wrapper library).

Leave a Comment