Cookies, Pixels and Local Storage Compared
How cookies, tracking pixels and web storage differ, who can read each one, and what clearing your browser actually removes.
Key takeaways
- Cookies travel to the server automatically with matching requests, which makes them the usual tool for logins and also for tracking.
- Local storage and session storage stay in the browser until a script reads them and sends the contents somewhere.
- A tracking pixel is a delivery method that reports an event, often carrying identifiers in its address or alongside it as cookies.
- Clearing site data removes stored identifiers on your device but does not erase records a company has already collected.
A cookie is a small value your browser stores and automatically sends back to a server. Local storage is a larger drawer in your browser that only page scripts can open. A pixel stores nothing at all: it's a request, usually for a tiny image, that tells a server something happened.
The three often work together. A script reads an ID from storage, then fires a pixel that reports the ID along with what you just did. Knowing which part does what makes browser settings and consent banners much easier to interpret.
Cookies: memory for a forgetful protocol
HTTP, the protocol browsers use to talk to web servers, treats each request as new. A cookie fixes that. The server includes a Set-Cookie header in a response, your browser saves the name and value, and it attaches them to later requests that match. The current core rules come from RFC 6265 and its ongoing revisions.
A typical header looks like this:
Set-Cookie: session=abc123; Path=/; Max-Age=3600; Secure; HttpOnly; SameSite=Lax Each attribute changes the behavior:
-
Max-AgeorExpiressets a lifetime. Without either, the cookie is a session cookie that's meant to vanish when the browsing session ends, though session restore features can bring it back. -
DomainandPathdecide which requests receive it. -
Securelimits it to encrypted HTTPS connections. -
HttpOnlyhides it from page scripts, which makes theft through injected code harder. -
SameSitecontrols whether it's sent on requests that start from another site.
Paste a header into the Set-Cookie attribute explainer to see each part described. For more on the mechanics, read how cookies work in HTTP.
First-party and third-party cookies
Whether a cookie is "third-party" depends on context. A cookie belonging to shop.example is first-party while you're on that store. If another site embeds something from shop.example, the same cookie would be third-party there.
Cross-site tracking relied on this. A company embedded on many sites could read its own cookie on each and recognize you. Browsers now push back. Some block third-party cookies, and some partition them, giving the embedded service a separate cookie jar for every top-level site so the jars can't be connected. A cookie that needs to work across sites generally has to be marked SameSite=None and Secure, and even then the browser or your settings may refuse it.
Policies differ between browsers and have changed repeatedly. Check your browser's privacy settings to see what yours does.
Local storage, session storage and IndexedDB
Web storage gives scripts a place to keep data without sending it with every request.
Local storage holds text key and value pairs for a particular origin, meaning the combination of scheme, host and port. It persists until a script, you or the browser removes it. Session storage works the same way but is tied to a single tab and disappears when that tab's session ends. IndexedDB is a fuller database for larger structured data, used by apps that work offline.
A script reads and writes local storage like this:
localStorage.setItem("theme", "dark");
localStorage.getItem("theme"); Local storage typically allows a few megabytes per origin, far more than the roughly 4 KB a single cookie can be counted on to hold. It has no expiry setting, and nothing like HttpOnly exists: any script running on the page, including a third-party one, can read the page's storage.
Storage is useful for preferences, drafts and offline data. It can also hold a tracking ID. Privacy laws that mention cookies often apply to similar storage technologies too, so a site can't necessarily avoid consent rules by switching drawers.
Pixels: the report, not the file
A tracking pixel began as a one-by-one transparent image. When your browser loads it, the server logs the request. The address can carry details in its query string, such as:
https://tracker.example.com/p.gif?event=purchase&order=1001 Alongside that, the server sees your IP address, browser headers and any cookie it's allowed to receive. That's enough to count a page view or record a conversion.
Today "pixel" often means a snippet of JavaScript supplied by an advertising platform. It can collect much more than an image could: page contents, button clicks, form fields and identifiers from storage. Sites sometimes install these without realizing how much they capture, which has caused problems on pages involving health, money or children.
Email uses the plain image version. Some mail apps block remote images or fetch them through a proxy, which blunts the signal. Tracking pixels in email explains the options.
How they work together
Here's a common sequence on a store's website. The details are generalized, but the pattern is widespread.
Some sites also send events from their own servers straight to the advertising company. Your browser takes no part in that step, so blockers can't intercept it, although the site still needs some identifier, such as a hashed email address or a click ID, to say who the event concerns.
Other places identifiers hide
Cookies and storage aren't the only options. The browser cache can be abused to remember values, which is one reason browsers now partition caches by site. Address parameters can carry IDs from one site to the next. And fingerprinting skips storage entirely by computing an identifier from your browser's characteristics.
Mobile apps have their own equivalents, including advertising IDs provided by the operating system. Deleting browser data does nothing to those.
Seeing and clearing what's stored
You can inspect all of this yourself. In most desktop browsers, open developer tools and look for a tab named Application or Storage. It lists cookies, local storage, session storage and databases for the current site. The Network tab shows pixel requests as the page loads; filtering by image or by a third-party domain helps. Browser developer tools for non-developers gives a gentle tour.
To remove data, use the browser's clear browsing data or site settings screen. Pay attention to the checkboxes. Clearing history alone may leave cookies and storage in place. Clearing "cookies and other site data" usually covers web storage too, and signs you out of sites.
You can also set the browser to delete site data when it closes, with exceptions for sites where you want to stay signed in. What clearing cache and cookies erases helps you choose.
A worked example: the abandoned cart
Say you add a pair of boots to a cart on a hypothetical store, then close the tab without buying. All three tools can play a part in what follows.
The store's first-party cookie holds a session ID, so the server can find your cart when you return. A script saves your recently viewed items in local storage, so the home page can show them without asking the server. A pixel from an advertising platform reports an "added to cart" event along with whatever identifier that platform can read or receive.
Days later you might see an ad for the same boots elsewhere. That's retargeting: showing ads to people based on something they did on a particular site. The store didn't need to tell the next site anything directly. The advertising platform did the connecting.
Each defense breaks a different link. Blocking third-party cookies makes it harder for the platform to recognize you on another site. A content blocker may stop the event from being sent at all. Clearing the store's site data empties your cart and recently viewed list but doesn't retract an event already reported. And if you gave the store your email address, it may be able to match you through that, with none of the browser tools involved.
What to block, and what to leave alone
Blocking every cookie breaks logins, carts and many ordinary features. A more useful middle ground:
- Allow first-party cookies so sites function.
- Block or partition third-party cookies.
- Use a content blocker to stop known tracking scripts and pixels from loading.
- Block remote images in email if you don't want open tracking.
- Periodically delete data for sites you no longer visit.
None of this deletes what companies already hold. If you want that gone, you'll need their privacy controls or a formal request where the law gives you one, as described in how to request a copy of your data.
Common questions
Are cookies dangerous?
A cookie is text and can't run as a program. The risks are tracking and theft: someone who steals a valid session cookie may be able to act as you until it expires. That's why Secure and HttpOnly matter.
Does rejecting cookies on a banner stop pixels?
It should stop whatever the banner says it controls, if the site is configured correctly. Many banners cover pixels and storage as well. Implementation varies, so a content blocker is a sensible backstop.
Why do sites I cleared still seem to know me?
You may have signed in again, kept the same IP address, followed a link carrying an ID, or been matched by fingerprint. Any of those can restore recognition without the old cookie.