Cookies are small files that websites store on your computer to remember information about you

A cookie is a text file, usually a few kilobytes in size, that a website saves to your device when you visit it. The website can then read that file on your next visit to remember who you are, what you did there, or what you prefer. Cookies are not programs — they cannot run code, install software, or damage your device. They are just data: a username, a login token, a shopping cart, a language preference, or a record that you clicked "do not show this again."

When you visit a website, the server sends a cookie to your browser with instructions on what to store and when to send it back. Your browser saves it in a dedicated folder. The next time you visit that same website, your browser automatically includes the cookie in the request, so the server knows it is you. This happens in the background without you seeing it happen.

Cookies exist because HTTP — the protocol websites use — is stateless. Each request from your browser to a server is independent; the server has no built-in way to know that two requests came from the same person. Cookies bridge that gap. Without them, you would have to log in again every time you clicked a link, and websites could not remember your preferences or shopping cart.

Key Takeaways

  • Cookies are text files websites store on your device to remember information about you across visits.
  • First-party cookies come from the website you are visiting; third-party cookies come from other companies and are often used for tracking and advertising.
  • You can see what cookies a website has stored, delete them, or block new ones from being created in your browser settings.
  • Cookies cannot run code or infect your device, but they can be used to track your browsing across multiple websites.

First-party cookies versus third-party cookies

First-party cookies come from the website you are actually visiting. If you log into your email, the email service sets a cookie so you stay logged in. If you add items to a shopping cart, the store sets a cookie to remember what you picked. If you change the text size on a news site, it sets a cookie to remember that preference. These cookies are useful and necessary for the website to function the way you expect.

Third-party cookies come from a different company than the one running the website you are on. A news site might embed an advertisement from an ad network, and that ad network sets a cookie on your device. A social media company might embed a "share" button on thousands of websites, and that button sets a cookie every time you visit any of those sites. Because the cookie is set by the same company across many different websites, that company can build a profile of your browsing habits — what sites you visit, what you search for, what you buy.

Third-party cookies are the main reason cookies have a reputation for invading privacy. A single advertising company might know that you visited a car website, then a mortgage site, then a baby products site, and use that information to guess your life stage and show you targeted ads. You never agreed to be tracked this way, and you may not even know it is happening.

How to see, manage, and delete cookies

Every major browser lets you view, delete, and block cookies. In Chrome, open Settings, go to Privacy and Security, then Site Settings, then Cookies. You will see a list of websites that have stored cookies on your device. You can delete all cookies at once, delete cookies from a specific site, or block cookies entirely (though this will break many websites).

Firefox, Safari, and Edge have similar controls. In Firefox, go to Settings, Privacy & Security, and scroll to Cookies and Site Data. In Safari on Mac, go to Preferences, Privacy, and Manage Website Data. In Edge, go to Settings, Privacy, Clear Browsing Data. All of them let you delete cookies from a specific date range, from specific sites, or all at once.

You can also set your browser to delete cookies automatically when you close it. This means you will stay logged into sites while you are browsing, but the cookies will vanish once you shut the browser down. The next time you open it, you will need to log in again — but you will not have persistent tracking cookies following you across the web.

The difference between session cookies and persistent cookies

Session cookies exist only while you are using a website. They are stored in your browser's memory and deleted as soon as you close the tab or browser. A session cookie might hold your login information or the contents of your shopping cart. Once you leave, it is gone.

Persistent cookies stay on your device for a set amount of time — days, weeks, months, or even years — even after you close the browser. A persistent cookie might remember your username so you do not have to type it in next time, or it might track your behavior across websites for advertising purposes. Persistent cookies are what allow third-party ad networks to follow you around the web.

Why websites use cookies and what they track

Websites use cookies for many legitimate reasons. A bank uses cookies to keep you logged in securely. An online store uses cookies to remember your shopping cart and your saved addresses. A video site uses cookies to remember where you stopped watching so you can resume later. A news site uses cookies to remember which articles you have read so it does not show you the same ones twice.

But cookies are also used for tracking. An advertising network uses cookies to follow you across hundreds of websites and build a detailed profile of your interests, location, income level, and browsing habits. A social media company uses cookies to track you even when you are not on its site, so it can show you ads based on what you have been looking at elsewhere. This tracking happens without your knowledge or consent on many websites.

Some websites also use cookies to detect if you are using an ad blocker, or to count how many unique visitors they get, or to test different versions of a page to see which one works better. These uses are less invasive than behavioral tracking, but they still involve collecting data about you.

Browser privacy features and cookie regulations

Browser makers have begun blocking third-party cookies by default. Apple's Safari has blocked them for years. Google Chrome is phasing them out. Firefox blocks them by default. This means fewer companies can track you across the web — though advertisers are developing new tracking methods that do not rely on cookies.

Some countries have also passed laws about cookies. The European Union's General Data Protection Regulation (GDPR) requires websites to ask for your permission before setting non-essential cookies. Many websites in Europe now show a cookie banner when you arrive, asking you to accept or reject tracking cookies. The California Consumer Privacy Act (CCPA) gives California residents the right to know what data is collected and to request deletion. Other U.S. states have passed similar laws.

These regulations do not prevent cookies from being used — they require websites to be transparent about it and to let you opt out. In practice, many websites make it easy to accept all cookies and difficult to reject them, so the rules help less than intended.

Cookies versus other tracking methods

Cookies are not the only way websites track you. Pixels are tiny invisible images embedded in websites and emails that phone home when you load them, telling a server that you visited. Local storage and IndexedDB are browser features that work like cookies but can hold much more data and are harder to delete. Fingerprinting is a technique that identifies you based on your browser type, screen resolution, installed fonts, and other details unique to your device.

These methods are harder for users to control and often persist even after you delete cookies. As cookies become less reliable for tracking, advertisers are shifting to these alternatives. Blocking cookies helps with privacy, but it is not a complete solution.

Frequently Asked Questions

Can cookies give me a virus or hack my computer?

No. Cookies are text files, not executable code. They cannot run programs, download files, or install malware. However, if a hacker steals a cookie that contains a login token, they could use it to access your account. This is why logging out on shared computers matters — it deletes the session cookie so someone else cannot use it.

Should I delete all my cookies?

Deleting all cookies will log you out of every website and erase your preferences. A better approach is to delete cookies from ad networks and tracking companies while keeping cookies from sites you use regularly. Most browsers let you delete cookies selectively by site. Alternatively, set your browser to delete cookies automatically when you close it.

What is a cookie banner and why do websites show them?

A cookie banner is the notice that appears when you visit many websites asking you to accept or reject cookies. It exists because of laws like GDPR and CCPA that require websites to get your permission before setting tracking cookies. Accepting all cookies is usually the default option, and rejecting them is often harder to find — this is intentional.

Do I need to enable cookies for websites to work?

Most websites require at least first-party cookies to function properly. If you block all cookies, you will not be able to log in, stay logged in, or use shopping carts. You can block third-party cookies without breaking websites — this stops ad networks from tracking you while letting sites remember you.