Skip to content
BENIBIX Learn

Local Storage

Development🌐 Web DevelopmentBrowser Code

Also known as localStorage, Web Storage, Session Storage

A small store in the browser for a site's data. It stays after you close it.

Think of it like

Think of it like a small drawer in your own desk. A site can leave notes there, and they wait until it comes back.

Example

Emma's site remembers that Lucy chose dark mode. It saves theme=dark in local storage and reads it on her next visit.

Why it matters

It lets a site remember small choices without a server or a login.

Definition

Local storage is a small store in the browser for a site's data. The data is kept as text. Unlike a cookie, it is not sent to the server with each request. The data stays even after the browser is closed, until the site or the user clears it. Each site gets its own space, usually around 5 megabytes. Its cousin, session storage, is wiped when the tab closes.

Example code

javascript
localStorage.setItem("theme", "dark");
localStorage.getItem("theme");  // "dark"
Save a setting, then read it back later.

Common mistake

Keeping passwords or login tokens in local storage. Any script on the page can read it.

Key takeaways

  1. 1
    Stays in the browser. Never sent to the server.
  2. 2
    Lasts after closing. Until it is cleared.
  3. 3
    Not for secrets. Any script can read it.

Compare

Learn it properly