Does Local Storage Need Consent? PECR Covers More Than Cookies
Swapping a cookie for localStorage.setItem does not get you out of the "cookie law". The UK rule never depended on cookies. It covers storing information on someone's device, or reading what is there, whichever API you use.
So local storage sometimes needs consent, depending on why you are storing the thing.
The rule does not mention cookies
The rule is regulation 6 of the Privacy and Electronic Communications Regulations 2003 (PECR). The current text, substituted by the Data (Use and Access) Act 2025 with effect from 5 February 2026, says that, subject to Schedule A1, a person must not "store information, or gain access to information stored" in a subscriber's or user's terminal equipment.
Your visitor's phone or laptop is the terminal equipment. The regulation also says that instigating the storage or access counts, so "the third-party script did it, not me" is a weak position if you put the script on the page.
The ICO's guidance on storage and access technologies names web storage explicitly, both localStorage and sessionStorage. A shorter lifetime may help you qualify for an exception, but it does not take you outside the rule.
Quick detour, because this catches people out: PECR is not limited to personal data. A random string, or a flag saying "has seen the popup", is still information. UK GDPR may also apply if you can link it to a person, but that is a second question and does not get you round the first.
Is anything purely on-device left alone?
Possibly, but do not build a policy on it. The ICO says PECR "may not apply" in some situations where information generated by the device's own software or hardware is not accessed by an outside entity and stays on the device.
That wording is hedged, and it covers less than "my data never reaches the server". An offline-first app whose JavaScript writes and reads its own records is still storing and accessing information. I would assume regulation 6 applies and look for an exception. That is my reading, and an exception is usually the easier argument to make.
The ICO's own web storage example is less friendly: a site writes audience categories to localStorage, an advertising service reads them later, and regulation 6 applies.
Sort each key by what it is for
Consent is the default route, and Schedule A1 sets out the exceptions. The ones a website is likely to care about are:
- Transmission: solely to carry out the transmission of a communication.
- Strictly necessary: needed to provide the online service the user asked for, including things such as security, fraud prevention and authentication.
- Statistics: solely to gather statistics so you can improve the service, with limits on sharing, clear information and a free, simple way to object.
- Appearance: solely to adapt how the site looks or works to the user's preferences, or otherwise enhance that, again with information and a way to object.
- Emergency assistance: locating someone who needs help.
Each exception attaches to a purpose, whatever the key or technology. If one stored ID serves login and advertising, the login use does not launder the advertising use.
What that means for common keys
Shopping baskets and login tokens
A basket the user is filling, or a token identifying them while they are logged in, fits "strictly necessary". The ICO's login example is limited to the duration of the visit, so a months-long "remember me" token needs more thought. An unticked "keep me signed in" box is a sensible way to make it something the user asked for.
Whether a token belongs in localStorage at all is a security question which a PECR exemption does not answer, since any script running on your origin can read it. An HttpOnly cookie is usually the better home.
Theme, language and layout
A saved dark-mode or language choice falls naturally under the appearance exception. No consent banner is needed, but you must still tell people and let them object. The ICO says you cannot rely solely on browser settings for that.
Some preferences may also qualify as strictly necessary. The ICO gives session cookies holding a preference as an example, provided they are not linked to a persistent identifier. localStorage outlives the session, so I would not stretch that example to cover it.
Analytics visitor IDs
Putting an analytics ID in localStorage leaves the analysis the same. The statistics exception can apply to genuine service-improvement counting, if you meet all its conditions. The ICO says it does not allow you to monitor or track individual visitors, so read your analytics product's behaviour carefully before claiming it.
Advertising and cross-site tracking
These need consent: the ICO says bluntly that online advertising purposes are not exempt. Consent has to come before the write or read, and carrying on browsing does not count.
Gate the write, and the read
The practical fix is to make every key declare its purpose and send all access through one place. This sketch covers three kinds of key:
const PURPOSE = {
basket: "necessary",
theme: "appearance",
adSegment: "consent",
};
// Wire these to your real settings controls.
const choices = { appearanceObjected: false, adsConsented: false };
function allowed(key) {
switch (PURPOSE[key]) {
case "necessary":
return true;
case "appearance":
return !choices.appearanceObjected;
case "consent":
return choices.adsConsented;
default:
return false; // unclassified keys are refused
}
}
export function save(key, value) {
if (allowed(key)) localStorage.setItem(key, value);
}
export function load(key) {
return allowed(key) ? localStorage.getItem(key) : null;
}
// Call after an objection or a withdrawal of consent.
export function purge() {
for (const key of Object.keys(PURPOSE)) {
if (!allowed(key)) localStorage.removeItem(key);
}
}
It is deliberately incomplete. The choices object forgets everything on reload, and real code has to remember an objection or refusal. Storing that choice solely to honour it can be strictly necessary; the ICO's example is a consent preference kept for a limited period, with prominent information about it.
The code also does nothing about the information you must provide: what you store, why, and for how long. localStorage has no expiry date, so if a value should die after 90 days, you have to delete it yourself.
Find out what your site really stores
Your source code won't show you everything, because dependencies write things too. To check:
- Open a fresh browser profile and load your site without touching the banner.
- In developer tools, look at the Application tab (Chromium) or Storage tab (Firefox).
- Check local storage, session storage, IndexedDB, Cache Storage and cookies, for each origin including iframes.
- Click "reject", browse a few pages, and look again.
- For every entry, write down who put it there, why, and which exception or consent covers it.
The interesting entries on that list are IndexedDB and Cache Storage. They are less famous than cookies, but the legal wording is about information and devices, so the same questions apply. A service worker that caches pages for offline use is storing information too. Whether it is strictly necessary depends on whether offline use is part of what the user asked for.
Getting it wrong costs more than it used to
The same 2025 reforms changed PECR enforcement. PECR Schedule 1 now applies the Data Protection Act 2018 penalty maximums, and regulation 6 falls in the higher band: £17.5 million, or for an undertaking 4% of worldwide annual turnover if that is higher.
That figure is a ceiling, so don't read it as the likely price of a stray theme key. The realistic job is smaller and duller: list your keys, give each a purpose, and delete the ones nobody can explain. There is usually at least one, left behind by a widget somebody removed in spirit but not in the template.