What Is a Session Cookie? Session Cookies vs Persistent Cookies Explained

October 24, 2026

jonathan

A session cookie is a tiny text file that a website stores in your browser and usually deletes when you close that browsing session. It helps the site remember you while you move from page to page. For example, it can keep you signed in while you check your account, add items to a cart, or fill out a form. MDN describes session cookies as cookies that are deleted when the current session ends [source: MDN].

TLDR

Session cookies are short-term cookies. Persistent cookies stick around longer. A session cookie might remember the 3 shirts in your cart while you browse, then vanish after you close the browser. A persistent cookie might remember your language choice for 30 days, so you do not have to click “English” every single time.

So, What Is a Session Cookie?

A session cookie is like a wristband at a theme park.

You get it when you enter. You use it while you are there. When you leave, it does not matter anymore.

On a website, the “theme park” is your active visit. The cookie tells the site, “Yes, this is still the same person.”

Without it, the web would feel broken. You would log in, click one link, and get logged out. You would add a product to your cart, open the checkout page, and the cart would be empty. Honestly, that feels like a prank.

A session cookie can store a small ID. That ID points to session data on the server. The cookie itself may not hold your name, password, or cart contents. It may just hold a random string, like a claim ticket.

Simple Example

Imagine you visit an online bookstore.

  • You log in.
  • The site gives your browser a session cookie.
  • You add two books to your cart.
  • You read reviews for 10 minutes.
  • You go to checkout.

The site still knows it is you. Nice. No drama.

Now you close the browser. Later, you return. The session cookie may be gone. The site may ask you to log in again.

That is the main idea.

Session Cookies vs Persistent Cookies

The big difference is time.

A session cookie is temporary. A persistent cookie has an expiry date.

Feature Session Cookie Persistent Cookie
How long it lasts Usually until the browser session ends Until its expiry date
Common use Login sessions, carts, forms Remember me, preferences, tracking
Expiry date No set expiry date Has a set expiry date
Privacy impact Usually lower Can be higher

The catch is that browsers can be weird. Some browsers restore tabs after closing. That may also restore session cookies. So “gone when the browser closes” is often true, but not always in the way normal humans expect.

What Do Session Cookies Do?

Session cookies do small jobs that make websites feel sane.

  • Keep you logged in during one visit.
  • Save cart items while you shop.
  • Remember form steps while you fill out a long form.
  • Protect checkout flows from getting mixed up.
  • Track basic page movement within one visit.

They are not magic. They are more like sticky notes. Very tiny sticky notes.

What Do Persistent Cookies Do?

Persistent cookies are the ones that hang around.

They may last for days, months, or even years. The website sets an expiry date. Your browser keeps the cookie until that date, unless you delete it first.

Common uses include:

  • Remember me login boxes.
  • Saved language choices.
  • Dark mode settings.
  • Location preferences.
  • Ad and analytics tracking.

Persistent cookies can be helpful. They can also be annoying. Ever clear your cookies and suddenly every site acts like it has never met you? Expect to waste 30 seconds closing cookie banners, picking a region, and signing in again. Great fun. Not really.

Are Session Cookies Safe?

Session cookies can be safe. But they need care.

A session cookie can act like a key. If someone steals it, they may be able to pretend to be you. That is why secure websites add protections.

Good cookie safety settings include:

  • Secure: sends the cookie only over HTTPS.
  • HttpOnly: blocks JavaScript from reading the cookie.
  • SameSite: helps reduce some cross-site request attacks.
  • Short idle timeout: logs users out after inactivity.

If a banking site logs you out after 5 or 10 minutes, it is not trying to ruin your day. It is reducing risk. Still, yes, it is mildly irritating when you looked away for one minute to find your account number.

Do Session Cookies Track You?

They can, but usually in a limited way.

A session cookie may track what you do during one visit. For example, it may record that you viewed 6 pages, added 1 item to your cart, and left before paying.

That helps site owners find problems. Maybe checkout takes too long. Maybe a shipping fee scares people away. Maybe the “Pay now” button is hiding like a tiny goblin.

Persistent cookies are more often used for long-term tracking. They can remember repeat visits. They can help build a profile over time. That is why privacy laws and cookie banners often focus on them.

First-Party vs Third-Party Cookies

There is another split to know.

First-party cookies come from the website you are visiting. If you are on example.com, the cookie comes from example.com.

Third-party cookies come from another domain. These are often used by ad networks, social widgets, or analytics tools.

A session cookie can be first-party. A persistent cookie can be first-party too. The same goes for third-party cookies. The category depends on who sets it, not just how long it lasts.

Why Websites Use Both

Most websites use a mix.

A store may use a session cookie to keep your cart alive while you shop. It may use a persistent cookie to remember your currency for 90 days. It may also use analytics cookies to count visits and spot drop-off points.

Used well, cookies make the web smoother. Used badly, they feel nosy.

Can You Delete Session Cookies?

Yes.

You can close your browser. You can also clear cookies in browser settings. Private or incognito mode usually deletes cookies when you close the private window.

Here is what happens when you delete cookies:

  • You may get logged out.
  • Your cart may reset.
  • Your saved settings may vanish.
  • Cookie banners may return. Sorry.

Deleting cookies can fix strange site bugs. It can also remove useful settings. So it is a blunt tool. Helpful, but a bit like turning the whole room off and on again.

Quick Tips for Users

  • Use private mode for temporary browsing.
  • Clear cookies if a site acts broken.
  • Avoid “remember me” on shared computers.
  • Log out from banking, email, and work tools.
  • Keep your browser updated for better cookie controls.

Quick Tips for Website Owners

  • Use session cookies for short login states.
  • Set Secure and HttpOnly on sensitive cookies.
  • Use SameSite where it fits.
  • Do not store passwords in cookies. Ever.
  • Explain cookie use in plain language.

The Easy Way to Remember It

Session cookie equals short visit memory.

Persistent cookie equals long-term memory.

Session cookies help a site remember you right now. Persistent cookies help it remember you later. Both can be useful. Both can be abused.

If a cookie disappears after your visit, it is probably a session cookie. If it remembers you next week, it is probably persistent. Simple enough. Tiny files, big impact.

Also read: