DevTools Surf logoDevTools Surf
AI / Modern DevAnimation / CSSAPI / Config
Sign in
DevTools Surf logoDevTools Surf
AI / Modern DevAnimation / CSSAPI / Config
Sign in
HomeInfo / GuidesCookies vs localStorage vs sessionStorage

About Cookies vs localStorage vs sessionStorage

Cookies vs localStorage vs sessionStorage preview - Info / Guides tool

Lifetime, security, cross-tab, cookie attributes, anti-patterns. Part of the DevTools Surf developer suite. Browse more tools in the Info / Guides collection.

Use Cases

  • Frontend developers choosing between cookies and localStorage for auth tokens
  • Security engineers auditing cookie attributes for CSRF protection
  • Mobile web devs understanding sessionStorage behavior across tabs
  • Full-stack devs implementing remember-me functionality with proper cookie flags

Tips

  • Use the comparison table to pick the right storage for your use case
  • Check the cookie attributes section for SameSite and Secure flags
  • Review the anti-patterns list to avoid storing sensitive data in localStorage

Fun Facts

  • HTTP cookies were invented by Lou Montulli at Netscape in 1994 to solve the shopping cart problem — HTTP had no way to remember state between requests.
  • The localStorage API was standardized in HTML5 (2009) with a 5 MB limit per origin — roughly 2.5 million characters of UTF-16 text.
  • The SameSite cookie attribute, first implemented by Chrome in 2016, became 'Lax' by default in Chrome 80 (February 2020) to mitigate CSRF attacks.

FAQ

Cookie, localStorage, sessionStorage — key differences?
Cookies sent with every request (server-visible); localStorage/sessionStorage client-only. Cookies have expiry; local is permanent until cleared; session clears on tab close.
Which should I use for auth tokens?
httpOnly + Secure cookies for session tokens (protected from JS). localStorage is vulnerable to XSS. If you must use localStorage, treat every token as compromise-possible.
What about SameSite?
Strict (no cross-site), Lax (cross-site for top-level navigation only), None (cross-site allowed, requires Secure). Lax is the safe default for most cookies.
Size limits?
Cookies: 4KB per cookie, ~50 per domain. localStorage: ~5MB per origin. sessionStorage: same as localStorage. For bigger client-side data use IndexedDB.

Related Info / Guides Tools

Docker BasicsSEO Basics for DevelopersREST API BasicsNext.js App Router BasicsConnect Your Site to GoogleGit Basics (First Hour)Kubernetes BasicsGraphQL vs REST
New · Flagshipsimple REST client

REST Handler — Collections, env vars, history, cURL converter

Send requests, save collections (nested), swap environments, and convert between cURL / Collection JSON / REST Handler YAML.

Open

Popular tools

The most-used tools on DevToolsSurf, one click away.

Encoding & crypto

  • Base64 Encode
  • Base64 Decode
  • URL Encoder
  • URL Decoder
  • Hash Generator
  • JWT Decoder
  • JWT Encoder
  • UUID Generator
  • ULID Generator
  • Password Generator
  • Bcrypt Hash Tester

Converters

  • CSV to JSON
  • JSON to CSV
  • XML to JSON
  • JSON to XML
  • HTML → Markdown
  • HTML → React JSX
  • cURL to Code
  • Collection JSON → cURL
  • Swagger to Collection JSON
  • JSON → Go Struct
  • JSON → TypeScript Types

JSON & YAML

  • JSON Formatter
  • JSON Validator
  • JSON Viewer
  • JSON Minifier
  • JSON Diff
  • JSONPath Tester
  • YAML Formatter
  • YAML to JSON
  • JSON to YAML

Text & regex

  • Regex Tester
  • Text Diff
  • Case Converter
  • Word Counter
  • Markdown Preview
  • Slug Generator
  • Lorem Ipsum Generator
  • Markdown → PDF

CSS & color

  • CSS Beautifier
  • Minify CSS
  • Color Converter
  • Gradient Generator
  • Contrast Checker
  • Color Palette Generator
  • Flexbox Playground
  • Tailwind → CSS

Generators

  • QR Code Generator
  • Mock Data Generator
  • Favicon Generator
  • .gitignore Builder
  • README.md Generator
  • Dockerfile Generator
  • Sitemap Generator

API & networking

  • REST Handler
  • HTTP Header Analyzer
  • IP Address Lookup
  • CIDR Calculator
  • User-Agent Parser
  • HTTP Status Reference
  • OpenAPI Viewer

Date & time

  • Timestamp Converter
  • Timezone Converter
  • Cron Expression Parser
  • Duration Calculator
  • Age Calculator
  • Date Format Converter

Images

  • Image Converter
  • Image Resizer (Batch)
  • SVG Optimizer
  • Base64 ↔ Image
  • WebP ↔ AVIF Converter
  • Image Compressor

PDF tools

  • PDF Merger
  • PDF Splitter
  • PDF Compressor
  • Markdown → PDF
  • EPUB → PDF
  • MOBI / AZW → PDF
  • DOCX → PDF
  • HTML → PDF

Resources

  • Community feed
  • Themes marketplace
  • Pricing & credits
  • Privacy policy
  • Terms of service
  • Sitemap
  • robots.txt

Your account

  • Sign in
  • Dashboard
  • Run history
  • My profile
  • Settings
DevTools Surf logo
DevTools Surf919+ tools

Fast · privacy-first · client-side · © 2026

Home·Feed·ThemesPricing·Sign inPrivacy·Sitemap Feedback