What is a cookie on a website?
A cookie is a small note that a website asks your browser to save. The next time you visit, your browser hands the note back. That is how the site remembers you.
Why is that needed? Websites have a short memory. Each time your browser asks for a page, the site treats it like a brand-new visit. A cookie is the sticky note that says, "Hey, it's the same person as before."
Cookies help with everyday things:
- Staying logged in so you do not type your password on every page.
- Remembering a shopping cart while you keep browsing.
- Saving settings like your language or dark mode.
// 1. You add shoes to your cart. The site replies: Set-Cookie: cart_id=8431 // 2. Every later request, your browser attaches the note: Cookie: cart_id=8431 // 3. The site looks up cart 8431 and shows your shoes.
A cookie is not a program. It cannot run code or read your files. It is only a short piece of text, like cart_id=8431. What matters is who reads it and what they do with it.
What is the difference between first-party and third-party cookies?
Most web pages are built from pieces. The main page comes from the site you typed in. But the ads, videos, and buttons on that page often come from other companies. Each piece can set its own cookie.
First-party cookie
Set by the site you are visiting. It remembers you on that site: your login, your cart, your language.
Who reads it: just that site.
Third-party cookie
Set by a different company whose content is on the page, such as an ad. If the same company is on many sites, its cookie can follow you to all of them.
Who reads it: the ad company, on every site it appears.
First-party cookies are mostly about helping the site work. Third-party cookies are mostly about advertising and tracking. Next, you will see why that second kind matters.
How do trackers follow you across websites?
Here is the trick. Imagine three different websites all show ads from the same ad company. In this demo we call it AdTrackr. It is made up, but real ad networks work in a similar way.
Every time an ad loads, your browser sends AdTrackr its cookie (ad_id=7Q42X). AdTrackr sees the same ID on all three sites, so it can add up what you do. That pile of guesses about you is called an ad profile.
Blocking breaks the chain. With third-party cookies blocked, AdTrackr cannot tell that the three visits came from the same person. Each site still works and still remembers your cart, because that is a first-party cookie. One thing blocking does not do: stop every kind of tracking. Keep reading.
Why would anyone build this? Ads that match your interests are worth more money to advertisers, so companies collect as much as they can. You can see the same idea at work in How Do Recommendation Algorithms Work? and in Why Apps Keep You Scrolling.
What other ways can websites track you? (Fingerprints and pixels)
Cookies are not the only way. If you delete or block them, some trackers use other tricks.
Browser fingerprinting
Your browser quietly shares small facts about itself so web pages can display properly: your screen size, your language, your time zone, and more. Each fact alone is boring. Millions of people share them.
But put several together and the mix gets rare. Think of describing a stranger: "wears glasses" fits lots of people. "Wears glasses, red backpack, left-handed, has a dog named Pepper" fits almost nobody. A browser fingerprint is a combination of traits that can be used to recognize a device without any cookie at all.
Tracking pixels
A tracking pixel is a tiny, invisible image, often just 1 pixel by 1 pixel. When a web page or an email loads it, your device asks the company's server for that image. The request itself is the message: "someone opened this."
The hidden square (cyan) is the pixel. Loading it tells the sender's server that you opened the email, when, and roughly where your internet connection is. Many email apps can block remote images to stop this.
Why this matters. Cookies, fingerprints, and pixels all feed the same thing: your digital footprint. Once data is collected and shared, it can be hard to pull back. See The Internet Never Forgets.
What do cookie banners really ask?
You have seen the pop-up: "We use cookies!" Many sites show one because laws in some places, such as the European Union's GDPR, require sites to ask before using cookies that are not strictly needed. The banner is really a menu of choices. Not every banner makes the choices easy to find, so it helps to know what each one means.
Watch for banner tricks
- A big bright "Accept all" button with a tiny gray "Manage" link. Pick the choice you want, not the one that shines.
- Hidden "Reject." If rejecting takes five clicks and accepting takes one, the banner is steering you.
- "Legitimate interest" toggles that are already on. Some banners list ad uses here. It is fine to switch them off.
Saying no to optional cookies never breaks the basics. The site still works.
How can you reduce online tracking?
You cannot be invisible online, but a few habits cut down a lot of tracking.
- Block third-party cookies. Open your browser's settings and look for Privacy or Cookies. Some browsers block third-party cookies by default. Others offer it as a setting you can switch on.
- Say no to optional cookies in banners. Choose Reject or Manage, then leave Analytics and Advertising off.
- Clear cookies now and then. This logs you out of sites and removes old tracking IDs. Your browser's settings let you clear everything or just one site.
- Review app permissions. Apps can track you without cookies. Check your phone's settings for which apps can see your location, contacts, camera, or microphone, and turn off what an app does not need.
- Use the privacy tools you already have. Many browsers have tracking protection, and many email apps can block remote images (which stops tracking pixels).
- Think before you share. The best way to keep data from being collected is not to type it in.
What does private mode actually do?
Private (or incognito) mode opens a window that forgets your history and cookies when you close it. That helps if you share a device. But it does not make you invisible. The websites you visit, your school or home network, and your internet provider can still see that visit while it happens. Private mode also does not hide you from fingerprinting. Think of it as a clean desk, not an invisibility cloak.
Not all tracking is evil. A site that counts visitors to fix a slow page, or remembers your cart, is doing something useful. The goal is not zero cookies. The goal is knowing who is collecting what, and choosing on purpose. If you ever see an app or site asking for more than it needs, trust that feeling and ask a trusted adult.
Quick quiz
1. Which cookie is most likely to follow you across many different websites?
2. You open a private browsing window and visit a website. What is true?
3. What is a browser fingerprint?
Key takeaways
- A cookie is a small note a site asks your browser to save. Many are helpful.
- Third-party cookies from ad companies can link your visits across sites into an ad profile.
- Fingerprints and tracking pixels track you without cookies.
- Cookie banners are choices. Reject optional cookies when you can.
- Block third-party cookies, clear cookies sometimes, and review app permissions. Private mode is not invisibility.
Cookies and tracking FAQ
What is a cookie in simple terms?
A cookie is a small note that a website asks your browser to save. The next time you visit, your browser hands the note back, so the site can remember things like that you are logged in or what is in your shopping cart.
What is the difference between first-party and third-party cookies?
A first-party cookie is set by the website you are visiting. A third-party cookie is set by a different company whose content, such as an ad or a button, is loaded on that page. Third-party cookies are the ones trackers use to recognize you across many sites.
Does private browsing stop websites from tracking me?
No. Private mode mostly stops your browser from saving your history and cookies on your own device after you close the window. Websites, your school or home network, and your internet provider can still see your visit while it happens.
Can I just block all cookies?
You can, but many sites will stop working properly, because logins and shopping carts rely on cookies. A better balance is to block third-party cookies, delete old cookies now and then, and say no to optional cookies in cookie banners.
Keep learning about your digital privacy
Tracking is one piece of your digital footprint. See why feeds know what you like in How Do Recommendation Algorithms Work?, why apps are built to hold your attention in Why Apps Keep You Scrolling, and why shared data sticks around in The Internet Never Forgets.
Want to go deeper? Explore the CodeHS Cybersecurity course or the Digital Literacy curriculum.
The sites and ad company in the demos (SneakerSwap, DinnerDash, GameBeat, AdTrackr) are made up for teaching.