PrivacyQuick

Cookies & tracking

What are website cookies? A plain-English guide

A cookie is a small piece of text that a website asks your browser to store and send back on later requests. Sites use cookies to keep you logged in, remember settings and, often, to track you for analytics and advertising.

  • Plain English
  • Written for website owners
  • Free to read

A cookie is a small piece of text, a name and a value plus a few settings, that a website asks your browser to store. On every later request to that site, your browser sends the cookie back automatically. That simple mechanism lets a website recognize you from one page to the next, which the web's underlying protocol, HTTP, can't do on its own. Cookies keep you logged in and remember what's in your cart. They're also the main way analytics and advertising tools recognize you across visits.

This guide explains how cookies work, the main types, what their settings mean, and why privacy laws care about them.

How cookies work

HTTP is stateless: each request a browser makes is independent, and the server doesn't remember the previous one. Cookies, introduced by Netscape in 1994, add memory to that conversation.

It happens in two steps. First, the server includes a Set-Cookie header in a response:

HTTP/1.1 200 OK
Content-Type: text/html
Set-Cookie: session_id=a3f9c2e7; Path=/; Secure; HttpOnly; SameSite=Lax

The browser stores the cookie. Then, on every following request to the same site that matches the cookie's settings, it sends the cookie back in a Cookie header:

GET /account HTTP/1.1
Host: www.example.com
Cookie: session_id=a3f9c2e7

The server looks up a3f9c2e7, finds the session it belongs to, and knows who you are. The cookie itself holds just a random ID. Your actual account data stays on the server.

JavaScript running on a page can also create and read cookies through document.cookie, unless a cookie is marked HttpOnly:

document.cookie = "theme=dark; Path=/; Max-Age=31536000; SameSite=Lax";
console.log(document.cookie); // "theme=dark; ..." (only non-HttpOnly cookies)

Many analytics and advertising tags set their cookies this way, from scripts loaded on your page.

What websites use cookies for

Almost every cookie serves one of three broad jobs:

  • Session management. Logins, shopping carts, multi-step forms, security tokens that protect forms from cross-site request forgery, and load-balancer routing.
  • Preferences. Language, currency, region, dark mode, or whether you've dismissed a notice. This also includes your cookie consent choice, which is itself stored in a cookie.
  • Tracking and measurement. Analytics tools assign a random ID so they can count returning visitors and follow a journey across pages. Advertising tools use IDs to measure conversions, build audiences for retargeting, and recognize the same browser across different websites.

Privacy rules treat these jobs very differently. That's why consent banners group cookies into categories such as necessary, functional, analytics and marketing, which our cookie categories guide explains.

Types of cookies

Cookies are usually described along two lines: how long they last, and who they belong to.

Session and persistent cookies

Cookies differ in how long they last:

  • Session cookies have no expiry date. The browser deletes them when the browsing session ends. In practice, browsers that restore your tabs on restart may keep them longer.
  • Persistent cookies have an Expires date or a Max-Age in seconds, and survive until then, or until you clear them.

Don't confuse a "session cookie" with a login session. A login cookie can be persistent ("remember me for 30 days"), and a session cookie can hold something unrelated to login.

Browsers also cap lifetimes. Chrome limits cookie expiry to 400 days, and Safari limits cookies set by JavaScript to seven days in many cases. Some regulators have their own expectations, which are covered in cookie lifespans.

First-party and third-party cookies

A first-party cookie belongs to the site shown in your address bar. A third-party cookie belongs to a different site, typically one whose content is embedded in the page, such as an ad server, a video player or a social widget. Because the same third party is embedded on thousands of sites, its cookie can recognize you across all of them. That's what made cross-site tracking possible.

Browsers treat the two very differently now. Safari and Firefox restrict third-party cookies by default, while Chrome's plans have changed several times. Note that "first-party" doesn't mean "harmless": many analytics and ad tools set first-party cookies from scripts on your page. The full picture is in first-party vs third-party cookies.

A cookie's attributes tell the browser where to send it, for how long and under what conditions:

AttributeWhat it doesExample
DomainWhich hosts receive the cookie. If omitted, only the exact host that set it. If set, that domain and its subdomains.Domain=example.com
PathLimits the cookie to URLs under a path.Path=/shop
Expires / Max-AgeWhen the cookie is deleted. Max-Age (in seconds) wins if both are set. Neither means a session cookie.Max-Age=2592000
SecureOnly send over HTTPS.Secure
HttpOnlyHide from JavaScript, which protects session cookies from theft through injected scripts.HttpOnly
SameSiteWhether the cookie is sent with cross-site requests: Strict (never), Lax (only top-level navigations), None (always; requires Secure).SameSite=Lax
PartitionedStores a third-party cookie separately for each top-level site (known as CHIPS), so it can't link activity across sites.Partitioned

When SameSite isn't set, Chrome and other Chromium browsers treat the cookie as Lax. That's why a cookie meant for cross-site use must explicitly say SameSite=None; Secure to work in those browsers.

What cookies can't do

Some common worries about cookies are misplaced:

  • They aren't programs. A cookie can't run code, read files on your computer or install anything.
  • A site can only read its own cookies. Browsers send a cookie only to the domain it belongs to. A tracker learns about your activity on other sites only because it's embedded on those sites too.
  • They're small. Browsers support at least about 4 KB per cookie and limit the number per domain, so cookies store identifiers rather than real data.

The real issues are privacy and security. A unique ID that follows you across sites and visits builds a detailed profile, and a stolen session cookie can let an attacker act as you.

Cookies and other browser storage

Cookies aren't the only way to store data in a browser. Websites also use:

  • localStorage, which keeps data per site with no expiry and isn't sent to the server automatically,
  • sessionStorage, which is similar but cleared when the tab closes,
  • IndexedDB, a larger database for offline apps,
  • tracking pixels, tiny images or requests that report a visit to a third party, often alongside cookies,
  • fingerprinting, which identifies a browser from its characteristics without storing anything.

Privacy rules in Europe don't care which technology is used. The question is whether information is stored on or read from the visitor's device. Our guide to localStorage and consent covers this.

Controlling cookies as a visitor

Every major browser lets you see and manage cookies without any technical tools:

  • Chrome: Settings → Privacy and security → Third-party cookies to block them, and Delete browsing data to clear them.
  • Safari: Settings → Privacy, where "Prevent cross-site tracking" is on by default, and Manage Website Data to remove what individual sites stored.
  • Firefox: Settings → Privacy & Security, where Enhanced Tracking Protection controls tracker blocking, and Cookies and Site Data to clear storage.

Menu names change from version to version, so search the settings page for "cookies" if they've moved. Private or incognito windows start with no cookies and delete everything when you close them, which is a quick way to see a site as a first-time visitor.

Blocking all cookies breaks logins and carts on most sites. Blocking only third-party cookies is a common middle ground: it stops most cross-site tracking while sites you visit directly keep working.

Why privacy laws regulate cookies

Two features of cookies attract regulators: they're stored on the user's own device, and they often carry identifiers that single someone out.

  • EU and UK. Article 5(3) of the ePrivacy Directive, and PECR in the UK, require consent before storing or accessing information on a device, unless it's strictly necessary for a service the user requested. Under GDPR Recital 30, cookie identifiers can be personal data. See the ePrivacy Directive guide.
  • United States. State laws such as the CCPA treat cookie IDs and browsing data as personal information. They let people opt out of the "sale" or "sharing" of that data for targeted advertising.
  • Elsewhere. Laws in Brazil, Canada, India and many other countries cover cookies when they collect personal data.

This is why websites show cookie banners: to tell visitors what's stored and, where required, to ask before non-essential cookies are set.

Next, read what a cookie banner is and whether you need one, session vs persistent cookies and cookie attributes like SameSite and HttpOnly.

See the cookies on your own site

If you run a website, you probably set more cookies than you think. Plugins, embeds and marketing tags all add their own. To find out:

  • Open your site in a browser and inspect it yourself. Our guide to checking cookies in Chrome DevTools walks you through it.
  • Run a free PrivacyQuick scan, which loads your pages in a real browser and lists the cookies, storage and third-party hosts it finds, with each one classified.
  • Compare the results with your cookie policy and banner, and make sure non-essential cookies wait for consent where the law requires it.

Frequently asked questions

Are cookies dangerous?

Cookies are plain text, not programs, so they can't run code or install malware. The real risks are privacy, when cookies are used to track you across sites, and security, when a session cookie is stolen and used to impersonate you.

What happens if I delete my cookies?

You'll be logged out of most sites, saved preferences such as language or cart contents may be lost, and consent choices will be forgotten, so you'll see cookie banners again. Tracking IDs reset too, until new ones are set.

How big can a cookie be?

Browsers generally support cookies of at least 4,096 bytes each, counting the name, value and attributes. They also limit how many cookies a single domain can store, so cookies are meant for small identifiers, not data.

Do all cookies need consent?

Not in the EU and UK. Cookies that are strictly necessary for a service the visitor asked for, such as a login session or shopping cart, are exempt. Analytics, advertising and most third-party cookies need consent first.

Check your own website in 30 seconds

Our free scanner lists every cookie and tracker your site sets, sorted into categories, before you add a banner.

Run a free cookie scan Start free

This guide is general information, not legal advice. Laws and regulator guidance change; check the current rules for your situation or ask a lawyer.