DEV Community

Sreekar Reddy
Sreekar Reddy

Posted on • Originally published at sreekarreddy.com

🍪 Cookies Explained Like You're 5

A wristband at a club

Day 44 of 149

👉 Full deep-dive with code examples


The Club Wristband

You go to a club. Pay at the door. Get a wristband.

Now you can:

  • Leave and come back
  • Staff knows you already paid
  • No need to pay again

Cookies are digital wristbands!


How They Work

  1. You visit a website
  2. Website gives your browser a "cookie" (a small piece of data)
  3. Next time you visit, browser shows the cookie
  4. Website recognizes you!
Visit 1: "Here's your cookie: user=alex"
Visit 2: Browser shows cookie → "Welcome back, Alex!"
Enter fullscreen mode Exit fullscreen mode

What Cookies Store

  • Login status (so you stay logged in)
  • Shopping cart items
  • Preferences (dark mode, language)
  • Tracking info (ads use this)

Types

Type What it means
Session Typically lasts for the current browsing session (but some browsers can restore them)
Persistent Has an expiry time/date; can last days/weeks/months
Third-party Set by a different site than the one you're visiting (often used for ads/analytics)

Privacy Concerns

Cookies can be used for tracking across websites. That's why many sites ask:
"Do you accept cookies?" 🍪


In One Sentence

Cookies are small pieces of data websites store in your browser to remember who you are and your preferences.


🔗 Enjoying these? Follow for daily ELI5 explanations!

Making complex tech concepts simple, one day at a time.

Top comments (0)