Please enable JavaScript to use CodeHS

Cybersecurity • Digital Privacy

What are cookies and online tracking?

Websites hand your browser tiny notes called cookies. Some notes keep you logged in. Others let ad companies follow you from site to site. Learn how it works, try it yourself, and learn how to take back some control.

Privacy ~12 min 3 interactive demos

Who Sets the Cookie?

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.



Beyond Cookies

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.

Demo 2

Your browser fingerprint (mini demo)

Nothing leaves your device. This demo reads a few harmless values from your own browser and shows them only on this page. It does not send, save, or share anything.

    Press the button to read your traits, then tick them one by one.

    Crowd of 64 people who look the same to a website.

    fingerprint code: (add a trait)

    Pretend each trait is shared by half of a crowd of 64 people. That is an illustration, not real data. Real numbers vary a lot, and real trackers can check many more traits than six.

    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.



    Take Back Control

    How can you reduce online tracking?

    You cannot be invisible online, but a few habits cut down a lot of tracking.

    1. 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.
    2. Say no to optional cookies in banners. Choose Reject or Manage, then leave Analytics and Advertising off.
    3. 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.
    4. 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.
    5. Use the privacy tools you already have. Many browsers have tracking protection, and many email apps can block remote images (which stops tracking pixels).
    6. 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.


    Check Yourself

    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.

    Common Questions

    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.