TapCub is live — analytics, insights and live chat, free on one platform
Glossary

What Is a Cookie on a Website? HTTP Cookies Explained

A cookie is a small text value a site asks your browser to store and send back. How Set-Cookie works, every attribute in one table, session vs persistent and first- vs third-party cookies, and which ones need consent.

Su He Reviewed by Ethan Brooks Also called HTTP cookie Last updated Nov 29, 2026 Glossary

Quick answer

A cookie on a website is a small piece of text (name and value) that the site asks your browser to store with a Set-Cookie header and that the browser sends back in a Cookie header on later requests, so the site can remember logins, carts, preferences or a returning browser.

What is a cookie on a website?

A cookie (HTTP cookie) is a small piece of text that a website asks your browser to store and then send back to the same site on later requests. The site sets it with a Set-Cookie response header; the browser returns it in a Cookie request header. That round trip lets a stateless protocol remember things between page loads: that you are logged in, what is in your cart, which language you picked, or that this browser has visited before.

A cookie is data, not a program. It cannot run code, read your files or install anything. What makes cookies matter for privacy is not what they are, but who sets them, how long they last and what the identifier inside them is used for. The mechanism is defined in RFC 6265 (IETF, April 2011), and every browser implements the same basic exchange.

How does a cookie work?

The exchange has two steps.

  1. The server sets it. In its response, the server includes a header such as:

Set-Cookie: cart_id=7f3a9c21; Max-Age=2592000; Path=/; Secure; HttpOnly; SameSite=Lax

  1. The browser sends it back. On every later request to a matching host and path, until the cookie expires, the browser adds:

Cookie: cart_id=7f3a9c21

Only the name and value travel back; the attributes stay in the browser and decide when the cookie is sent. In the example, Max-Age=2592000 is 2,592,000 seconds, which is 30 days (2,592,000 ÷ 86,400). The whole header line is 85 characters, far below the size limit.

RFC 6265 section 6.1 sets the minimum a general-purpose browser should support: at least 4,096 bytes per cookie (name, value and attributes together), at least 50 cookies per domain and at least 3,000 cookies in total. Sites that store more than a short ID usually hit problems on the first limit, because cookies are sent with every request and large ones slow every page and image load.

Cookie attributes explained

AttributeExampleWhat it doesIf you leave it out
ExpiresExpires=Wed, 30 Dec 2026 08:00:00 GMTSets an end date for the cookieCookie is a session cookie
Max-AgeMax-Age=2592000Lifetime in seconds; wins over Expires if both are setFalls back to Expires, then session
DomainDomain=example.comSends the cookie to that domain and all its subdomainsSent only to the exact host that set it
PathPath=/accountSends the cookie only for URLs under that pathDefaults to the path of the request URL
SecureSecureSends the cookie only over HTTPSSent over HTTP too
HttpOnlyHttpOnlyHides the cookie from JavaScript (document.cookie)Scripts on the page can read it
SameSiteSameSite=LaxStrict: same-site requests only; Lax: also top-level navigations from other sites; None: all requests, and requires SecureSome browsers apply Lax
PartitionedPartitionedStores a separate copy per top-level site; requires SecureOne shared copy

Two practical rules follow from the table. A login or cart cookie should carry Secure, HttpOnly and SameSite=Lax or Strict unless there is a specific reason not to. And Domain widens scope rather than narrowing it: omit it if only one host needs the cookie. MDN also documents the __Host- prefix, which forces Secure, Path=/ and no Domain, so a subdomain cannot overwrite the cookie.

Session vs persistent cookies

The lifetime split depends only on whether Expires or Max-Age is present.

Session cookiePersistent cookie
How it is setNo Expires or Max-AgeExpires or Max-Age present
When it is deletedWhen the browser session ends (the browser decides when that is)At the expiry time, or when the user clears it
Typical useLogin state for one visit, checkout steps"Remember me", language choice, analytics or ad identifiers
ExampleSet-Cookie: sid=a1b2Set-Cookie: lang=de; Max-Age=31536000

"Session" refers to the browser session, not to an analytics session. Browsers that restore tabs on restart may keep session cookies much longer than people expect, so do not rely on a session cookie to log someone out.

First-party vs third-party cookies

Who sets a cookie matters more for privacy than how long it lasts. A first-party cookie belongs to the site in the address bar: shop.example sets cart_id and reads it back on its own pages. A third-party cookie belongs to another domain whose resource is embedded on the page, such as an ad or social widget at tracker.example. Because that domain is embedded on many sites, its cookie can link one browser's visits across all of them.

CookieSet byCan it follow you across sites?Typical consent position in the EU
First-party, strictly necessary (cart, login, load balancing)The site you visitNoExempt from consent
First-party, preferences (language, theme)The site you visitNoUsually exempt if the user asked for the feature
First-party, analyticsThe site, via an analytics scriptNoNeeds consent in most EU countries
Third-party, advertising or trackingAn embedded domainYesNeeds consent

In the EU and EEA the rule comes from Article 5(3) of the ePrivacy Directive (2002/58/EC, rewritten by Directive 2009/136/EC). Storing information on a user's device, or reading information already stored there, needs the user's consent after clear and comprehensive information. There are two exemptions: storage needed only to transmit a communication, and storage strictly necessary to provide a service the user explicitly asked for.

A decision rule you can apply to each cookie on your site:

  1. Would the feature the user requested break without it? A cart cookie on a shop or a session cookie after login: exempt.
  2. Does it remember a choice the user made? A language cookie set when they picked a language: usually exempt.
  3. Is it for measurement, advertising, personalization the user did not ask for, or cross-site tracking? It needs consent before it is set.

Article 5(3) is about storage and access on the device, not about the word "cookie". Local storage, pixels that read stored IDs and device fingerprinting fall under the same rule, which is why "we use local storage instead" does not remove the consent question. When the cookie data identifies a person, the GDPR applies on top. Outside the EU, rules differ by country and state. This page is a definition, not legal advice.

Cookies are often confused with other ways a site can keep data in the browser.

CookielocalStoragesessionStorage
Sent to the server automaticallyYes, with every matching requestNoNo
SizeAbout 4 KB each (RFC minimum)Several MB per originSeveral MB per origin
Readable by JavaScriptYes, unless HttpOnlyYesYes
LifetimeSession or until expiryUntil clearedUntil the tab closes
Can be set by the serverYes, via Set-CookieNoNo

The practical difference: only cookies reach the server without extra code, which is what makes them useful for logins and also what makes them a tracking vehicle. Cookieless analytics avoids both cookies and these stores, and counts visitors by other means.

How to see the cookies a site sets

  1. Open the site in a fresh private window so old cookies do not mix in.
  2. Open developer tools and go to Application (Chrome, Edge) or Storage (Firefox), then Cookies, and select the site.
  3. Read each row: name, domain, expiry, size and the HttpOnly, Secure and SameSite flags. A domain that differs from the address bar is a third-party cookie.
  4. In the Network tab, click the first document request and look for Set-Cookie in the response headers, to see which cookies the server sets before any script runs.
  5. Reject non-essential cookies in the banner, reload, and check that only strictly necessary ones remain.

Common mistakes

  • Setting analytics cookies before consent. In the EU the banner must come first; loading the script and asking afterwards defeats the purpose.
  • Treating a long Max-Age as harmless. A cart cookie that lives 10 years outlives the cart; keep lifetimes close to the purpose.
  • Storing personal data in the value. Put an opaque ID in the cookie and keep the email or name on the server.
  • Forgetting Secure and HttpOnly on login cookies, which exposes them to network sniffing and script injection.

How TapCub counts visitors without cookies

Take a site that wants traffic numbers but does not want an analytics cookie in its cookie list. In TapCub that is the default:

  1. Install the website script. In the default anonymous mode, the script writes neither a cookie nor local storage. You can confirm it with the inspection steps above: no TapCub entry appears under Cookies.
  2. Visitors are still separated. The collector derives a visitor ID from a salted hash of the address and browser data, then discards the address. In the default balanced preset the salt is site-level, so returning visitors can be compared; the strict preset rotates the salt daily. See how cookieless counting works.
  3. Set region rules in Configuration › Privacy center. The default rule for the EEA and the UK is collection tier 2 with consent required. Without analytics consent, hits drop to tier 1 (anonymous aggregate), and pageviews and custom events are still recorded.
  4. Turn on identification only if you need it. Identified mode writes a device ID once consent is granted and the tier is 3. Whether your site needs a banner depends on your configuration and local law; see do I need a consent banner.

TapCub does not manage your other cookies or run a consent banner; it only measures, within the tier the visitor's consent allows.

Sources

Was this explanation clear?

We use your answers to fix and expand this page.

Su He

Data Analyst

Explores traffic sources, conversion funnels, and retention, using clear metric definitions and concrete examples to explain what the numbers mean.

FAQ

Questions people ask

Short answers to the follow-up questions that come up most.

Still have a question?

Chat with the team behind TapCub — we usually reply within a few hours on business days.

Are cookies on a website bad?

No. A cookie is only stored text and cannot run code. Cookies that keep you logged in or hold your cart are needed for the site to work. The privacy concern is with third-party and tracking cookies that link your visits across many sites, which is why the EU requires consent before they are set.

Should I accept or reject cookies?

Rejecting non-essential cookies keeps strictly necessary ones (login, cart, security), so the site still works; you mainly lose remembered preferences and the site loses some measurement and ad personalization. Accepting allows analytics and advertising cookies within what the banner lists. You can change your choice later in the site settings or by clearing cookies.

How long do cookies last?

A session cookie has no Expires or Max-Age and is deleted when the browser session ends. A persistent cookie lasts until its Expires date or Max-Age seconds run out, for example Max-Age=2592000 is 30 days, or until you clear it. The site chooses the lifetime when it sets the cookie.

What is the difference between cookies and cache?

Cookies are small name-value pairs a site stores to remember state and that are sent back to the server with requests. The cache stores copies of files such as images, scripts and pages so they load faster, and is not sent back to the server. Clearing cookies logs you out; clearing the cache only makes the next load slower.

See this number on your own site

Add one script tag for web and apps, and the first reports fill in within minutes.

See your data clearly. Find your growth.

Every click, backed by data. Install one line of code and see your first numbers in a minute.

No credit card · Free plans for analytics and chat · Cookieless analytics