Local Storage

A browser-based web storage for data, similar to cookies but with greater capacity and no automatic transmission.

Local Storage is a browser-based web storage that allows websites to store data locally. It is similar to cookies but with greater capacity and without automatic transmission to the server.

What is Local Storage?

Local Storage is part of the Web Storage API and allows key-value pairs to be stored in the browser. Data persists even after the browser is closed and has no expiry date.

Local Storage vs. Cookies

  • Capacity – Local Storage: ~5-10 MB, Cookies: ~4 KB
  • Transmission – Local Storage is not automatically sent to the server
  • Expiry – Local Storage has no automatic expiry
  • Access – JavaScript only, not HTTP headers
  • Security – HttpOnly and Secure flags are not supported

Session Storage

Session Storage is similar to Local Storage, but data only exists for the duration of the session (browser tab). When the tab is closed, the data is deleted.

Typical uses

  • Offline application data (PWA)
  • Caching API responses
  • Storing application state
  • Partially completed forms
  • User preferences

Legal perspective

Local Storage is subject to the same rules as cookies. Under the ePrivacy Directive and the GDPR, storing data on the user's device requires consent unless the data is strictly necessary.

Need to sort out cookies on your website?

Consentio provides a GDPR-compliant cookie banner with Google Consent Mode v2 support. Implementation in 5 minutes.

Get started for free