> Local storage vs cookies under GDPR: why localStorage needs consent like cookies, which uses are exempt and how to check what your site stores.
>
> Canonical: https://www.flowconsent.com/en/blog/local-storage-vs-cookies-gdpr

[Comparisons](https://www.flowconsent.com/en/blog?category=comparisons)

# Local storage vs cookies: what GDPR and ePrivacy require

By Roland Vekemans · Published 20 November 2026 · 7 min read

In short

Local storage and cookies both keep data in the visitor's browser, and European law treats them the same way. Article 5(3) of the ePrivacy Directive covers any information stored on or read from a device, whatever the technology, so a value written to `localStorage` needs prior consent unless it is strictly necessary for a service the user asked for. Moving a tracking identifier from a cookie to local storage does not remove the banner. It only makes the tracker harder to see.

Developers often pick local storage because it is simple, holds more data and is never sent to the server. Privacy teams then discover that analytics or marketing tools have been writing identifiers there for months, outside the scope of the cookie banner. This guide covers the technical differences, what the GDPR and the ePrivacy rules actually say, which uses are exempt, and how to check your own site. If you need a refresher on the basics first, start with our guide to [what cookies are and how they work](https://www.flowconsent.com/en/blog/what-are-cookies-types-how-they-work).

## Local storage vs cookies: the technical differences

Cookies, local storage and session storage are three ways for a website to keep data in the browser. They behave differently, and those differences explain why tools choose one over the other.

**Cookies** are small text values, around 4 KB each. The browser attaches them automatically to every HTTP request sent to the matching domain, which is why servers use them for sessions and logins. A cookie can be shared across subdomains, can have an expiry date, and can be marked `HttpOnly` so that JavaScript cannot read it. A cookie without an expiry date is a session cookie; one with an expiry date is a [persistent cookie](https://www.flowconsent.com/en/blog/persistent-cookies-definition-lifetime-examples) that survives after the browser is closed.

**Local storage** (`window.localStorage`) is a key-value store that most browsers limit to about 5 MB per origin. Its data is never sent to the server automatically: only JavaScript running on the same origin (same scheme, host and port) can read or write it. It has no expiry date. A value stays until the site deletes it or the user clears site data.

**Session storage** (`window.sessionStorage`) works like local storage but is tied to a single tab. Its data disappears when the tab is closed.

Two practical consequences follow. First, anything in local storage is readable by any script loaded on the page, including third-party tags, so it should never hold secrets such as authentication tokens. Second, browsers are tightening their rules: since 2020, Safari deletes all script-writable storage, local storage included, for sites the user has not interacted with in seven days. Local storage is not a way around browser privacy protections.

## Does GDPR apply to local storage?

Two laws apply, and they look at different things.

The [ePrivacy Directive](https://www.flowconsent.com/en/laws/eprivacy-directive) regulates the device. Its Article 5(3) requires consent for "the storing of information, or the gaining of access to information already stored" in the user's terminal equipment. The text never mentions cookies by name. It is technology-neutral, so it applies to `localStorage`, `sessionStorage`, IndexedDB and any similar mechanism. The Court of Justice confirmed in Planet49 (C-673/17, 1 October 2019) that this rule applies whether or not the stored information is personal data.

The GDPR regulates personal data. As soon as local storage holds an identifier that can single out a browser or a person, such as a random visitor ID, a user ID or a hashed email, the processing that follows must also meet GDPR requirements: a legal basis, transparency, retention limits. When that legal basis is consent, it must meet the conditions of [valid GDPR consent](https://www.flowconsent.com/en/blog/gdpr-consent-validity-requirements): freely given, specific, informed, unambiguous and as easy to withdraw as to give.

Regulators have said this explicitly:

- The European Data Protection Board, in its Guidelines 2/2023 on the technical scope of Article 5(3), confirms that the rule covers storage mechanisms beyond cookies, along with pixels and other techniques.
- The CNIL's guidelines on cookies and other trackers (17 September 2020) list HTML5 local storage among the trackers they cover.
- The UK ICO's guidance on PECR applies to "cookies and similar technologies" and names HTML5 local storage as one of them (see our page on [UK GDPR and PECR](https://www.flowconsent.com/en/laws/uk-gdpr-pecr)).
- In Germany, § 25 TDDDG uses the same wording as the directive: storing or accessing information in the end device. In Spain, Article 22.2 of the LSSI speaks of data storage and retrieval devices.

## When local storage needs consent, and when it does not

The ePrivacy rule has only two exceptions: storage needed to transmit a communication, and storage strictly necessary to provide a service the user explicitly requested. The purpose decides, not the technology.

Uses that are usually exempt:

- a shopping cart kept in local storage between pages;
- the visitor's consent choice itself, so the banner does not reappear on every page;
- a language or display setting the user chose themselves;
- data a web app needs to work, such as an unsent draft or an offline queue the user started.

Uses that need consent:

- an analytics or session-replay tool that stores a visitor ID to recognise returning visitors;
- an A/B testing tool that keeps a visitor ID to assign variants and measure results;
- advertising or retargeting identifiers;
- third-party embeds that write identifiers on load. YouTube's privacy-enhanced mode, for example, writes a device identifier (`yt-remote-device-id`) to local storage before any click.

The same test applies as for cookies. Our list of [strictly necessary cookies with examples](https://www.flowconsent.com/en/blog/strictly-necessary-cookies-examples) works for local storage keys too: a cart key is exempt, a visitor ID used for statistics is not.

Not sure what your own pages write? Check in 30 seconds which cookies and trackers your site sets with the [free cookie scanner](https://www.flowconsent.com/en/scan).

## Three myths about local storage and consent

**"Local storage is not a cookie, so the banner does not apply."** The law does not regulate cookies, it regulates storing and reading information on a device. A key in `localStorage` is covered exactly like a cookie.

**"The data never leaves the browser, so it is not tracking."** A script can read the value and send it in its next network request at any time. A visitor ID read from local storage and attached to an analytics call is tracking, even if no cookie travels with the request.

**"Session storage is fine because it is deleted when the tab closes."** Short lifetime does not create an exemption. A session identifier used for analytics still needs consent; it just expires sooner.

## How to check what your site stores in local storage

You can inspect local storage in any desktop browser:

1. Open your site in a private window, without accepting anything.
2. Open the developer tools (F12, or Cmd+Option+I on a Mac).
3. In Chrome or Edge, go to the **Application** tab, then **Storage > Local storage** and **Session storage**. In Firefox and Safari, the tab is called **Storage**.
4. Select your domain and read the keys. Repeat for each embedded domain listed.
5. Refuse consent in the banner, reload, browse to a second page and check again. Nothing non-essential should appear.

Key names often reveal the tool that wrote them, through a vendor name or prefix. When a key is unclear, search for its name or check which script sets it. The same panel shows cookies, and our guide on [how to check cookies on a website](https://www.flowconsent.com/en/blog/how-to-check-cookies-on-a-website) walks through each browser in detail.

## What to do when consent is refused or withdrawn

A compliant setup handles local storage in three moments.

**Before consent.** The tool that writes the key must not run. That means blocking the script itself, not only its cookies. A banner that only deletes cookies after the fact misses local storage completely.

**After a refusal.** The choice should be stored (a strictly necessary key or cookie is fine for that) and respected on every page. A common failure is a choice that is not read on the second page, so tags fire again.

**After a withdrawal.** Withdrawing must be as easy as consenting (Article 7(3) GDPR). Stop the tools from reading their keys and remove the identifiers they left, otherwise a returning tool can pick up the old ID. Then list your local storage keys alongside your cookies in your cookie policy, with their purpose and lifetime.

FlowConsent is a concrete example of this approach: the banner blocks non-essential scripts before consent rather than cleaning up after them, so nothing is written to local storage until the visitor agrees.

## How FlowConsent handles local storage

FlowConsent treats local storage as a tracker, like cookies. Non-essential scripts are blocked until the visitor consents, so an analytics or marketing tool cannot write its identifier in advance. The automatic cookie scan inventories what your site sets, and the refusal scan goes further: it loads your page in a real browser from Europe, refuses consent, then records every tracker request, non-essential cookie and local storage entry that still appears, including on a second navigation, where a badly stored choice usually leaks. Each choice is logged as exportable proof of consent, and Google Consent Mode v2 is built in. FlowConsent is free up to 25,000 sessions per month, then €14.99 per month for Pro up to 100,000 sessions. See how the [refusal scan verifies your pages](https://www.flowconsent.com/en/doc/compliance-verification).

[Back to the blog](https://www.flowconsent.com/en/blog)

Share this article · [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fwww.flowconsent.com%2Fen%2Fblog%2Flocal-storage-vs-cookies-gdpr) · [X](https://twitter.com/intent/tweet?url=https%3A%2F%2Fwww.flowconsent.com%2Fen%2Fblog%2Flocal-storage-vs-cookies-gdpr)

Questions

## Common questions on this topic.

Can't find your question? Write to us, we answer fast.

[Write to us](https://www.flowconsent.com/en/demo)

### Does local storage need cookie consent?

Yes, unless it is strictly necessary. Article 5(3) of the ePrivacy Directive covers any information stored on or read from the user's device, not only cookies. A localStorage key used for analytics, A/B testing or advertising needs prior consent. Keys that keep a shopping cart, the consent choice itself or a setting the user chose are usually exempt, because they serve a service the user asked for.

### Is local storage a cookie?

Technically no. A cookie is sent with every HTTP request to its domain, can expire and can be hidden from JavaScript. Local storage stays in the browser, has no expiry date and is only readable by scripts on the same origin. Legally the difference does not matter: privacy law regulates storing and reading information on a device, so both fall under the same consent rule.

### Does session storage need consent?

It follows the same rule as local storage. Session storage is deleted when the tab closes, but a short lifetime does not create an exemption. If a script stores a session identifier there to measure visits or test variants, it needs consent. If it only keeps data the user needs during the visit, such as a form step or a cart, it is usually strictly necessary.

### Is it safer to use local storage instead of cookies?

Not for privacy, and often not for security. Moving an identifier to local storage does not avoid the consent requirement. On the security side, any script on the page can read local storage, so a cross-site scripting flaw exposes everything in it, while an HttpOnly cookie stays out of reach of JavaScript. Keep authentication tokens out of local storage.

### How do I remove local storage data when consent is withdrawn?

First stop the tool from running, by blocking its script. Then delete the keys it created with localStorage.removeItem() for each key, or use the opt-out function the vendor documents. Avoid localStorage.clear() unless you want to erase everything, including the cart and the stored consent choice. Finally, check in the browser developer tools that the identifiers are gone after a reload.

Read next

## Keep reading.

[All articles](https://www.flowconsent.com/en/blog)

[Marketing tools · 9 May 2026](https://www.flowconsent.com/en/blog/hotjar-cookies-gdpr-compliance)

### [Hotjar and GDPR: cookies, session recordings and compliance](https://www.flowconsent.com/en/blog/hotjar-cookies-gdpr-compliance)

[Hotjar is a behavioural analytics tool that sets tracking cookies. This guide explains why consent is mandatory and how to configure Hotjar for GDPR compliance.](https://www.flowconsent.com/en/blog/hotjar-cookies-gdpr-compliance)

[Read the article ](https://www.flowconsent.com/en/blog/hotjar-cookies-gdpr-compliance)·

[Regulation · 2 April 2026](https://www.flowconsent.com/en/blog/eprivacy-regulation-cookies-europe-what-changes)

### [ePrivacy Regulation: what changes for cookies](https://www.flowconsent.com/en/blog/eprivacy-regulation-cookies-europe-what-changes)

[The ePrivacy Regulation will replace the 2002 cookie directive. Wider tracker definitions, browser-based consent and uniform EU rules: here is what to prepare for.](https://www.flowconsent.com/en/blog/eprivacy-regulation-cookies-europe-what-changes)

[Read the article ](https://www.flowconsent.com/en/blog/eprivacy-regulation-cookies-europe-what-changes)·

[Platform guides · 13 July 2026](https://www.flowconsent.com/en/blog/nextjs-cookies-gdpr-compliance-guide)

### [Next.js cookie consent and GDPR: the complete compliance guide](https://www.flowconsent.com/en/blog/nextjs-cookies-gdpr-compliance-guide)

[How to collect valid cookie consent in a Next.js app, from App Router installation and SPA navigation to Google Consent Mode v2 and server-side consent checks.](https://www.flowconsent.com/en/blog/nextjs-cookies-gdpr-compliance-guide)

[Read the article](https://www.flowconsent.com/en/blog/nextjs-cookies-gdpr-compliance-guide)

## Make your site compliant today.

Free up to 25,000 sessions a month. No credit card, no commitment.

[Create my banner](https://app.flowconsent.com/auth/sign-up?utm_source=flowconsent.com\&utm_medium=referral\&utm_campaign=general) · [Scan my site](https://www.flowconsent.com/en/scan)
