localStorage

A browser feature that saves small text values for a website so they are still there after the page is closed and reopened.

In more detail

A theme toggle stores the user's choice, such as "dark", in localStorage and reapplies it on the next visit. Values are strings, limited to a few megabytes, and readable by any script on the same site, so they must not hold secrets.

Example

In the browser: It holds around five megabytes per origin and is readable by any script on the page, so never store secrets there. Calls are synchronous and throw QuotaExceededError when full.

Related terms

Taught in

References