# Local Storage

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

**Field:** Software Development  
**Category:** Web Development  
**Also known as:** localStorage, Web Storage, Session Storage

## 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.

## 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

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

## Example code

```javascript
localStorage.setItem("theme", "dark");
localStorage.getItem("theme");  // "dark"
```

Save a setting, then read it back later.

## Why it matters

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

## Common mistake

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

## Three principles

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

## Related terms

- [HTTP Cookie](https://learn.benibix.com/term/development/cookie)
- [Front End](https://learn.benibix.com/term/development/front-end)
- [Document Object Model (DOM)](https://learn.benibix.com/term/development/dom)
- [JavaScript](https://learn.benibix.com/term/development/javascript)

## Told apart from

- [Cookie vs Local Storage](https://learn.benibix.com/compare/cookie-vs-local-storage): A cookie and local storage both keep small bits of data in the browser. A cookie goes to the server with every request. Local storage stays in the browser and only your page's code reads it.

## Taught in

- [Cookies and Local Storage](https://learn.benibix.com/learn/development-web/cookies-and-local-storage): HTML, CSS and JS, 14/14

---

Source: https://learn.benibix.com/term/development/local-storage
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-19
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
