Internet & Web

Cookies vs Local Storage

Cookies and local storage both keep information in a browser, but they have different security, size, lifetime and request behaviors.

Cookies can be sent automatically with matching HTTP requests and can use attributes such as Secure, HttpOnly and SameSite. Local storage is read by page JavaScript and is not automatically attached to requests.

Two practical examples

Example 1. A server can use a Secure, HttpOnly session cookie to maintain a login.

Example 2. A site can store a non-sensitive theme preference in local storage.

What to check in practice

  • Identify the exact device, software version or service involved before changing a setting.
  • Record the current configuration so you can reverse a change that causes problems.
  • Test one variable at a time and confirm the result using reliable measurements or logs.
  • Use the official documentation for model-specific limits, compatibility and safety requirements.
Important consideration

Do not store session secrets in local storage without a careful threat model. Configure cookie scope and security attributes, and avoid keeping unnecessary personal data in either store.

Common question

What is the first thing to do? Start by identifying the exact use case and the system involved. Then verify the relevant settings or measurements before making changes. A general explanation is a starting point, not a substitute for checking your own environment.

TryHook publishes independent educational explainers. Product names and technical standards belong to their respective owners. Some pages may eventually contain clearly disclosed affiliate links; editorial explanations are not paid endorsements.

Explore more in Internet & Web

Continue with related beginner-friendly guides.

How Does the Internet Work?Read guideHTTP vs HTTPSRead guide