Glossary · Web Development

Local Storage

LOH-kul STOR-ijnoun

Local storage is a browser feature that lets a website save key-value data on the user's device with no expiration date.

Part of speech
noun
Pronunciation
LOH-kul STOR-ij
Origin
From 'local,' meaning on the user's own device, and 'storage.' Part of the Web Storage API introduced with HTML5 around 2009.

What is Local Storage?

Local storage is a browser feature that lets a website save small pieces of data directly on the user's device, as key-value pairs, with no built-in expiration date. Whatever a site stores there stays put across page reloads and even after the browser is closed and reopened, until the site's code removes it or the user clears their browser data. This gives websites a simple, persistent place to remember things on the visitor's own machine without sending that information back to a server each time.

Mechanically, local storage is part of the Web Storage API that browsers expose to the JavaScript running on a page. A site saves data by giving it a name and a value, reads it back later by name, and can update or delete entries as needed. The values are stored as text strings, so more complex data is typically converted to a text format before being saved and converted back when read. Storage is scoped to a single origin, meaning one website's stored data is walled off from other sites and cannot be read by them. Capacity is limited, commonly a few megabytes per site, which is generous for small settings but not meant for large files. Importantly, local storage is synchronous and lives entirely in the browser; it is never automatically sent to the server, unlike cookies.

The name simply describes what it is: "local," meaning on the user's own device, and "storage." It was introduced as part of the Web Storage API that arrived with HTML5 around 2009, giving developers a cleaner, roomier alternative to cramming small bits of state into cookies, which were the older and more limited tool for remembering information in the browser.

For a business, local storage matters because it improves the user experience by letting a site remember preferences and state without a round trip to the server. It can hold a chosen theme such as dark mode, remember items a shopper added to a cart, cache data so a page loads faster on a return visit, or keep track of whether a user has dismissed a notice. These conveniences make a website feel more responsive and personal, and because the data stays on the device, they reduce unnecessary server requests, which can lower costs and speed things up.

The nuances and common mistakes are mostly about security and appropriate use. The biggest mistake is storing sensitive information there, such as authentication tokens or personal data, because any JavaScript running on the page, including malicious scripts injected through a cross-site scripting vulnerability, can read local storage freely. For that reason security-conscious teams often prefer more protected mechanisms for credentials. Local storage also has no expiration, so stale data can linger unless the site cleans it up, and its size limits and text-only nature make it unsuitable for large or complex datasets. Local storage relates to JWTs and authentication, which are sometimes stored there despite the risks, and to the fetch mechanisms and CORS rules that govern how a page talks to servers. Used for non-sensitive preferences and caching, it is a handy and reliable tool.

Why it matters

Local storage remembers user preferences and cart contents between visits, creating a smoother, faster return experience.