A browser cookie is a small piece of data, usually under 4 KB, that a website's server sends to your browser, which stores it and sends it back with later requests to the same site. Cookies exist because HTTP is stateless: without them, a site would forget you between clicks. They remember logins, shopping carts and preferences, but third-party cookies can also track you across many sites.
Key takeaways
- A cookie is a small name-value record set by a server and sent back by your browser on later requests.
- First-party cookies run the site you are on; third-party cookies track you across sites and are now restricted.
- You can control cookies in browser settings, block third-party cookies, and clear them regularly without breaking logins permanently.
Every cookie banner asks the same question, and most people click "accept all" just to make it disappear. But cookies are not one thing: some keep you signed in, some remember your cart, and some follow you from site to site for advertising.
This guide explains what browser cookies actually are, how they work, the types you will meet, the real privacy and security risks, and how to control them in Chrome, Safari, Firefox and Edge — without breaking the sites you use.
What are browser cookies?
A browser cookie, also called an HTTP cookie or web cookie, is a small piece of data that a server sends to a user's web browser, which the browser may store and send back with later requests to the same site.
That definition comes from MDN Web Docs, and the formal standard is IETF RFC 6265, published in April 2011. Cookies exist because HTTP, the protocol your browser uses to fetch pages, is stateless: each request arrives with no memory of the previous one. Without cookies, a site would forget you between two clicks.
A cookie is tiny by design. RFC 6265 asks browsers to support at least 4,096 bytes per cookie, at least 50 cookies per domain and at least 3,000 cookies in total. A cookie usually holds an identifier that points to data stored on the server, rather than the data itself — like a coat-check ticket, not the coat.
How do cookies work?
Cookies travel in HTTP headers, the lines of metadata sent before the page itself. The whole cycle has five steps, and nothing is installed or runs on its own.
- You open a page. Your browser asks the site's server for it, with no cookie for that site yet.
- The server answers with a Set-Cookie header, for example
Set-Cookie: theme=dark; Max-Age=2592000, asking the browser to keeptheme=darkfor 30 days. - The browser stores the cookie with the site's domain, path and expiry time.
- On the next request to that site, the browser adds a Cookie header:
Cookie: theme=dark. - The server reads it and responds accordingly — here, with the dark version of the page. Sign-in works the same way, with a random session ID instead of a theme.
A script on the page can also set a cookie through document.cookie, but JavaScript cannot create or overwrite a cookie flagged HttpOnly, and it cannot read the Set-Cookie header itself.
What are the types of browser cookies?
Cookies are sorted along three independent axes — lifetime, origin and purpose — so one cookie belongs to one group in each. The purpose grouping matters most for privacy law and for the banners you see.
| Axis | Type | What it means | Example |
|---|---|---|---|
| Lifetime | Session cookie | No expiry date; deleted when the browser session ends | A shop's cart ID |
| Lifetime | Persistent cookie | Kept until its expiry date, for days or months | Stay signed in for 30 days |
| Origin | First-party cookie | Set by the site in the address bar | Your sign-in on that site |
| Origin | Third-party cookie | Set by another domain embedded in the page | An ad network's visitor ID |
| Purpose | Strictly necessary | Site cannot work without it | Login, cart, load balancing, security |
| Purpose | Preferences | Remembers your choices | Language, theme, region |
| Purpose | Statistics | Measures how the site is used | Analytics, page views |
| Purpose | Marketing | Advertising and tracking | Ad targeting, remarketing |
Only strictly necessary cookies are exempt from consent under the EU ePrivacy Directive, which is why banners ask about the other categories. Session cookies sound short-lived, but browsers that restore your tabs on restart can keep them alive much longer than you expect.
First-party vs third-party cookies: what is the difference?
A first-party cookie is set by the domain shown in the address bar. It runs that site's features: keeping you signed in, remembering your cart, storing your language. Blocking first-party cookies breaks sites.
A third-party cookie is set by a different domain whose content is embedded in the page, such as an advertising network, a social media button or a video player. The same advertising domain can recognize your browser on thousands of unrelated websites, which is what makes cross-site tracking possible.
The browser landscape has split on third-party cookies. Safari and Firefox block them by default. Google Chrome, by contrast, abandoned its long-planned phase-out: in April 2025 Google confirmed it would keep its existing approach to third-party cookie choice in Chrome and would not roll out a new standalone prompt, so Chrome users manage them through settings, and Incognito mode blocks them by default.
What do cookie attributes do?
A cookie has one mandatory part, the name and value, and several attributes the server can set. Each attribute narrows when the browser sends the cookie back, and three of them are security controls.
| Attribute | What it does |
|---|---|
| Domain | Which hosts receive the cookie; setting it includes all subdomains |
| Path | Which URL paths receive it; /account scopes it to that section |
| Expires / Max-Age | When it dies; Max-Age wins if both are set; zero or negative deletes it |
| Secure | Only sent over HTTPS, never over plain HTTP |
| HttpOnly | Hidden from JavaScript, so scripts cannot read it — mitigates cross-site scripting |
| SameSite | Whether it is sent with cross-site requests: Strict, Lax or None |
| Partitioned | Stored per top-level site, so an embedded cookie cannot track across sites |
SameSite deserves a closer look, because it is the attribute that most directly stops cross-site abuse. With SameSite=Strict, the cookie is only sent to the site that set it. With Lax, it is also sent when you navigate to the site by clicking a link. The full standard is RFC 6265, and MDN documents all three values in its Set-Cookie reference.
Cookie name prefixes add another layer: a cookie named __Secure- must be set with the Secure flag from an HTTPS page, and one named __Host- must also have no Domain attribute and a path of /.
What are cookies used for?
Cookies do the quiet work that makes the modern web usable. Without them, most sites would be unusable, which is why blocking all cookies is a bad idea.
- Keeping you signed in. A session cookie holds a random ID that proves who you are on each request, without sending your password again.
- Shopping carts. The cart ID survives from page to page because the cookie carries it.
- Preferences. Language, theme, region and consent choices are stored as cookies so the site remembers them next visit.
- Security. Cookies carry anti-forgery tokens that stop cross-site request forgery, and load balancers use them to keep you on the same server.
- Analytics. First-party analytics cookies count visits and popular pages, without identifying you by name.
- Advertising. Third-party cookies build a profile of the sites you visit, so advertisers can target and measure ads — the use that drives most privacy concern.
Are cookies safe? The real risks
Cookies are text, so they cannot run code, install software or act as a virus. The risks come from what a stolen or misused cookie lets an attacker do.
Session hijacking is the most serious risk. If an attacker steals your session cookie — over an unencrypted connection, through malware, or from a compromised network — they can use it to act as you on that site without knowing your password. The Secure flag, short expiry times and HTTPS everywhere reduce this risk.
Cross-site scripting (XSS) lets an attacker's script run on a trusted page and read cookies through JavaScript. The HttpOnly flag blocks that read, which is why session cookies should always carry it.
Cross-site request forgery (CSRF) tricks your browser into sending a request to a site where you are signed in, with your cookies attached. SameSite=Lax or Strict stops most CSRF, because the cookie is not sent on the cross-site request.
Tracking and profiling is the privacy risk most people actually experience. Third-party cookies let advertising companies build a picture of your browsing across sites, which is then used for ad targeting and, in some cases, sold onward. This is a privacy harm, not a security breach, but it is the reason consent laws exist.
Why do websites ask about cookies? GDPR and consent
The banners exist because of law, not because sites enjoy showing them. In the EU, the ePrivacy Directive requires consent before storing or accessing information on a user's device, except for strictly necessary cookies. The GDPR adds rules on the personal data cookies can carry.
That is why a compliant banner offers real choices — accept all, reject all, or pick categories — rather than a single "accept" button. In the UK, the Information Commissioner's Office takes the same position, and in California the CCPA and CPRA give residents rights to opt out of the sale or sharing of personal information collected through cookies.
For site owners, the practical rule is simple: get consent before setting non-essential cookies, record the choice, and honor a rejection. For users, the practical rule is equally simple: reject the categories you do not need, because the site must still work.
How to manage and delete cookies
You do not need to delete cookies constantly, but you should know how to control them. The steps are similar in every browser, under privacy or site settings.
Chrome
Go to Settings, then Privacy and security, then Third-party cookies. You can block third-party cookies, block them in Incognito only, or allow them. To delete cookies for one site, click the padlock or tune icon in the address bar, then Site settings, then Clear data.
Safari
Safari blocks third-party cookies by default and uses Intelligent Tracking Prevention to limit tracking. To clear cookies, go to Settings, then Privacy, then Manage Website Data, and remove data for specific sites or all sites.
Firefox
Firefox blocks third-party tracking cookies by default under Enhanced Tracking Protection. To clear cookies, go to Settings, then Privacy and Security, then Cookies and Site Data, and choose Clear Data or Manage Data for specific sites.
Edge
Edge offers tracking prevention at Balanced level by default, which blocks many third-party trackers. To delete cookies, go to Settings, then Privacy, search, and services, then Clear browsing data, and choose cookies and other site data.
After clearing cookies, you will be signed out of most sites and will need to sign in again. That is normal, and it is also a useful security habit after using a shared or public computer. You can check what your browser reveals about you with our free WebRTC leak test.
What is replacing cookies?
Because third-party cookies are restricted in Safari and Firefox and unpopular with regulators, the industry has built alternatives — none of which fully replaces them yet.
- First-party data: sites ask you directly for an email or account, instead of inferring you from tracking. This is the most durable replacement.
- Partitioned cookies (CHIPS): a cookie stored per top-level site, so an embedded service works without tracking you across sites.
- Storage Access API: an embedded site asks permission to access its cookies in that context, with user approval.
- Privacy Sandbox APIs: Google's Topics, Protected Audience and Attribution Reporting were built to replace cookie-based advertising and measurement, though Google announced in October 2025 that it would retire several of them.
- Local storage and fingerprinting: sites sometimes use localStorage, IndexedDB or device fingerprinting instead of cookies. These are harder to control than cookies, which is why regulators treat them the same way.
For privacy, the direction is clear even if the technology is unsettled: less cross-site tracking, more first-party relationships, and more control in the browser. Your own choices — blocking third-party cookies and rejecting marketing cookies — already move you most of the way there.
The bottom line
Browser cookies are the web's memory. First-party cookies keep you signed in and remember your preferences; third-party cookies track you across sites. Neither is inherently good or bad — it depends on who sets the cookie and what they do with it.
Block third-party cookies, reject marketing cookies you do not need, and clear cookies after using a shared computer. You can check your browser's privacy exposure with our free what is my IP tool.
For the rest of your browsing, keep the habits in our Wi-Fi security guide alongside your cookie settings.
Frequently asked questions
What are browser cookies in simple terms?
Browser cookies are small text notes a website asks your browser to keep, so the site can remember you next time. They hold things like a login session ID, items in a shopping cart, or a language choice, and your browser sends them back to the site on later visits.
Are browser cookies dangerous?
Cookies themselves are just text and cannot run code or install software, so they are not viruses. The risk is what they enable: tracking across sites, session hijacking if a login cookie is stolen, and profiling for advertising. Secure, HttpOnly and SameSite attributes reduce those risks.
What is the difference between first-party and third-party cookies?
A first-party cookie is set by the site shown in your address bar, and it usually runs that site's features such as logins. A third-party cookie is set by another domain whose content is embedded in the page, such as an ad network, and it can recognize your browser across many different sites.
Should I accept all cookies?
No. Accept strictly necessary cookies, which keep the site working, and decide about the rest. Rejecting marketing and tracking cookies usually costs you nothing except personalized ads, and most sites must still work without them.
What happens if I delete all cookies?
You will be signed out of most websites, shopping carts will empty, and preferences such as language or theme will reset. The sites still work, and you can sign in again. Deleting cookies does not delete your accounts or your browsing history.
Do cookies track my location?
Cookies do not usually store your location directly, but they can store an identifier that a company links to location data from your IP address or device. Advertising cookies are the main way companies build a profile of the sites you visit.
Are cookies the same as cache?
No. Cookies store small pieces of state such as a session ID, while the cache stores copies of files such as images and pages so they load faster. Clearing cookies signs you out of sites; clearing cache only makes pages load more slowly once.
Can I block third-party cookies without breaking websites?
Usually yes. Safari and Firefox block third-party cookies by default, and most sites work fine. Some embedded logins and widgets may break, in which case you can allow cookies for that specific site or use the site directly instead of through an embed.
Sources
The engineers and analysts who build Cysoro's domain scanner, email-authentication checks and free security tools. We test what we write about every day — SPF, DKIM, DMARC, certificates, look-alike domains and phishing — and check each guide against the relevant standards, government guidance and vendor documentation.
Checked against IETF RFC 6265, MDN Web Docs on HTTP cookies and Google's Privacy Sandbox documentation on third-party cookies.
How we write and fact-check →