Tech Terms Explained Open in the app →

Local Storage

Frontend · Beginner · 4 min read

What is it?

Local storage is a browser feature that lets a website save simple key-value data on the user's device, which persists even after the browser closes.

Explain like I'm 5

Local storage is like a notebook your browser keeps for each website: the site can jot down notes and read them back later, even after you close and reopen it.

Why was it created?

Cookies are small and sent to the server on every request. Local storage was added to store larger client-only data conveniently.

Where is it used?

  • Saving user preferences
  • Caching data for offline use
  • Remembering UI state
  • Storing drafts locally

Why should developers care?

Front-end apps use it for preferences, drafts, and offline data, so it's a common everyday tool (this very site uses it for bookmarks).

How does it work?

JavaScript reads and writes string key-value pairs via the localStorage API. The data stays on the device, scoped to that site's origin, until the code or the user clears it. It is not sent to the server automatically.

Real-world example

A web app saves your dark-mode choice in local storage so the site stays dark the next time you visit.

Common use cases

  • Theme and UI preferences
  • Offline-friendly data
  • Remembering recent items
  • Client-only state

Advantages

  • Larger capacity than cookies
  • Persists across sessions
  • Simple key-value API
  • Not sent to the server (less request overhead)

Disadvantages

  • Strings only (must serialize objects)
  • Readable by JavaScript (not for secrets)
  • Synchronous API can block
  • Per-origin and per-device only

When should you use it?

For non-sensitive, client-only data you want to persist in the browser.

When should you avoid it?

For secrets or auth tokens (XSS-readable) and for data the server needs every request (use cookies).

Alternatives

CookiesSession storage (cleared on tab close)IndexedDB (larger/structured data)

Related terms

CookieSessionSerialization

Interview questions

Beginner

  • What is local storage?
  • How is it different from a cookie?

Intermediate

  • What data type does local storage hold?
  • Why shouldn't you store tokens in it?

Senior

  • When would you choose IndexedDB over local storage?
  • What are the security implications of local storage?

Common misconceptions

  • "Local storage is secure for tokens" — it's readable by any JavaScript on the page, so it's risky for secrets.
  • "Local storage gets sent to the server like cookies" — it stays on the device unless your code sends it.

Fun facts

  • Local storage only holds strings, so objects must be serialized (often via JSON).
  • Unlike session storage, it persists after the tab or browser closes.

Timeline

  • 2010s — Web Storage (localStorage) becomes broadly supported

Learning resources

Quick summary

Local storage saves persistent, client-only key-value data in the browser, ideal for preferences and offline data but not for secrets.

Cheat sheet

  • Browser key-value storage
  • Persists across sessions
  • Strings only; not for secrets
  • Stays on device (not auto-sent)

If you remember only one thing

Local storage persists simple client-only data in the browser — great for preferences, wrong for secrets.