Best practices

Persistent cookies: what they are, how long they last and examples

Article contents

Most cookies you meet on the web are persistent cookies. They are the reason a site still knows your language, your cart or your "keep me signed in" choice a week later, and the reason an analytics tool counts you as a returning visitor. This guide explains what a persistent cookie is, how its lifetime works, real examples, how persistent cookies differ from session cookies and what EU law requires. For the bigger picture (first-party and third-party cookies, purposes, the law), start with our guide to what cookies are and the types of cookies.

A persistent cookie (also called a permanent, stored or non-session cookie) is an HTTP cookie that the browser writes to disk and keeps across browsing sessions. What makes it persistent is a single attribute. The server, or a script on the page, sets the cookie with either:

  • an Expires attribute, which gives a date and time, for example Expires=Wed, 14 Apr 2027 10:00:00 GMT;
  • or a Max-Age attribute, which gives a number of seconds, for example Max-Age=2592000 for 30 days.

A typical response header looks like this: Set-Cookie: lang=fr; Max-Age=31536000; Path=/; Secure; SameSite=Lax. The browser stores lang=fr for one year and sends it back with every request to that site until then.

If both attributes are present, Max-Age wins: that is the rule in RFC 6265, the standard that defines HTTP cookies. If neither is present, the cookie is a session cookie and disappears when the browsing session ends.

The word "permanent" is misleading. No cookie lasts forever. A persistent cookie is deleted when its expiry date passes, when the user clears cookies, or when the site overwrites it with a date in the past or Max-Age=0, which is the standard way to delete a cookie.

How long do persistent cookies last?

Three things decide the real lifetime of a persistent cookie: the website, the browser and the user.

The lifetime set by the website

The site chooses the value. It can be a few minutes (a short security token), a few weeks (a remembered login) or two years (the default for the Google Analytics _ga cookie). Some tools also refresh the expiry on every visit. Google documents that _ga gets a new two-year expiry each time a hit is sent, so a visitor who comes back regularly keeps the same identifier indefinitely. We detail this in our article on the _ga, _gid and _gat cookies.

The limits set by browsers

Browsers no longer accept any lifetime. The current draft of the cookie standard (RFC 6265bis) asks browsers to cap expiry dates at 400 days, and Chrome has applied this cap since version 104, released in 2022. A cookie set for five years in Chrome is stored for 400 days.

Safari goes further for some cookies. Its Intelligent Tracking Prevention limits cookies written by JavaScript (through document.cookie) to 7 days. Cookies set by the server in an HTTP header are not affected by that specific rule. This is one reason analytics and advertising vendors have moved part of their tracking to the server side.

The user

Visitors can delete cookies at any time, block them, or browse in a private window. In private mode, persistent cookies behave like session cookies: they are deleted when the private window closes.

Examples of persistent cookies

You will find persistent cookies on almost every website. Common examples:

  • Consent cookie: your cookie banner stores the visitor's choice so it does not ask again on every page. The CNIL considers that keeping this choice for about 6 months is good practice.
  • Language or region preference: a cookie such as lang remembers the version of the site you chose.
  • "Keep me signed in": a login token kept for days or weeks, instead of a session that ends when the browser closes.
  • Analytics: _ga and _ga_<ID> from Google Analytics 4, 2 years by default.
  • Advertising: _fbp from the Meta Pixel, around 90 days according to Meta, or _gcl_au from Google Ads, 90 days. See our article on the _fbp and _fbc cookies.

Many of these are third-party or tracking cookies used to recognize you across visits. Our guide to tracking cookies explains how they follow users and how to block them.

Persistent cookies vs session cookies

The difference comes down to the expiry attribute, but it has practical consequences:

  • Lifespan: a session cookie ends with the browsing session; a persistent cookie lives until its expiry date, within the browser's cap.
  • Storage: a session cookie is kept in memory; a persistent cookie is written to disk.
  • Memory across visits: only a persistent cookie can recognize a visitor who comes back the next day.
  • Privacy weight: a long-lived identifier can link visits over months, which is why regulators look closely at lifetimes.

Both are cookies in the legal sense, and both can be first-party or third-party. Our article on first-party vs third-party cookies covers that other distinction.

Yes, unless they are strictly necessary. Article 5(3) of the ePrivacy Directive requires consent before storing or reading any information on a user's device, whatever its lifetime. Duration does not decide whether consent is needed. Purpose does.

The exemption covers cookies that are strictly necessary for a service the user asked for, and the cookie that stores the consent choice itself. A persistent cookie can be exempt: a cart kept for a few days or a consent cookie, for example. But in its Opinion 04/2012 on the cookie consent exemption, the Article 29 Working Party (now the EDPB) noted that persistent login cookies, which keep a user authenticated across browser sessions, are not exempt. The "keep me signed in" box is the user's choice, so it needs to be presented as one.

Lifetime still matters for compliance. GDPR requires data to be kept no longer than necessary, and the CNIL recommends a maximum of 13 months for cookies that require consent. Our article on cookie retention and the 13-month rule explains how to apply it, including for tools whose defaults exceed it.

Not sure which persistent cookies your site sets, or for how long? Run the free cookie scanner and see in 30 seconds which cookies your site sets, with their lifetimes.

Are persistent cookies a security or privacy risk?

A persistent cookie is a small text file. It cannot run code or install malware. The risks come from what it contains and how long it lasts:

  • Tracking: a long-lived identifier, especially a third-party one, lets a company recognize the same browser over months.
  • Account takeover: a stolen long-lived login token gives access to an account until it expires. Sites should mark such cookies Secure and HttpOnly, use SameSite, and revoke tokens on logout.
  • Stale data: a cookie set years ago may still send data for a purpose nobody remembers.

Shorter lifetimes reduce all three risks. That is also why browsers keep tightening their caps.

How to see and delete persistent cookies

In Chrome, Edge or Firefox, open the developer tools (F12), then the Application tab (Storage in Firefox) and select Cookies. The "Expires / Max-Age" column shows a date for persistent cookies and "Session" for session cookies. Safari shows the same data in its Web Inspector, under Storage. Our step-by-step guide on how to check cookies on a website covers each browser.

To delete them, clear site data from the browser settings, or remove a single cookie from the same developer panel.

What website owners should do

  1. List your persistent cookies and their real lifetimes, as set on your site, not as written in an old policy.
  2. Check each lifetime against its purpose. Shorten what you control, such as the GA4 cookie_expires setting, and aim for 13 months at most for consent-based cookies.
  3. Block non-essential cookies until consent. A persistent analytics cookie set on the first page view is the most common finding in audits.
  4. Declare every cookie and its duration in your cookie policy, using the duration as it is really set.
  5. Ask again when consent expires or when your purposes change.

A consent platform such as FlowConsent takes care of points 3 and 4: it holds back tracking scripts until the visitor accepts, and it lists each cookie with its duration in the banner.

How FlowConsent handles persistent cookies

FlowConsent blocks scripts before consent, so analytics and advertising tools cannot write their persistent cookies until the visitor accepts. The cookie list shown in the banner is generated from the services you activate: each entry carries its name, purpose, provider, type and duration as it must be displayed to visitors, so you do not maintain Google's lifetimes by hand. The automatic cookie scan compares what your site really sets with what your banner declares, and alerts you when a cookie is missing. Google Consent Mode v2 is built in, and proof of consent can be exported. The cookie declaration documentation explains the setup. FlowConsent is free up to 25,000 sessions per month, then Pro at €14.99 per month up to 100,000 sessions.

Questions

Common questions on this topic.

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

What is an example of a persistent cookie?

A common example is the language cookie that remembers which version of a site you chose, kept for months. Others are the cookie that stores your consent choice, a "keep me signed in" login token, the Google Analytics `_ga` cookie (2 years by default) and the Meta Pixel `_fbp` cookie (around 90 days). All of them carry an expiry date, so they survive when you close the browser.

What is the difference between persistent and non-persistent cookies?

A non-persistent cookie, or session cookie, has no Expires or Max-Age attribute. The browser keeps it in memory and deletes it when the browsing session ends. A persistent cookie has one of those attributes, is written to disk and stays until its expiry date or until the user deletes it. Only persistent cookies can recognize a visitor from one visit to the next.

How long can a persistent cookie last?

The website sets the lifetime, from a few minutes to several years. Browsers cap it: Chrome has limited cookie expiry to 400 days since version 104 in 2022, and Safari limits cookies written by JavaScript to 7 days. For cookies that need consent, the French CNIL recommends 13 months at most. Some tools, like Google Analytics, refresh the expiry on every visit, which keeps the same identifier much longer.

Are persistent cookies safe?

A persistent cookie is a text file: it cannot run code or install malware. The risks are tracking, because a long-lived identifier can link your visits over months, and account takeover if a long-lived login token is stolen. Sites reduce these risks with short lifetimes and the Secure, HttpOnly and SameSite attributes. As a visitor, you can delete persistent cookies at any time in your browser settings.

Do persistent cookies require consent under GDPR?

In the EU, the consent rule comes from article 5(3) of the ePrivacy Directive, read together with GDPR. A persistent cookie needs prior consent unless it is strictly necessary for a service the user asked for, such as a cart or the cookie that stores the consent choice. Lifetime alone never exempts a cookie, and persistent login cookies that keep users signed in across sessions are not exempt.

Make your site compliant today.

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