0Pricing
HTML Academy · Lesson

localStorage vs sessionStorage

Understand the lifetime and scope of each storage type.

Web Storage API Overview

The Web Storage API provides two client-side key-value stores: localStorage (persistent across sessions) and sessionStorage (cleared when the tab closes). Both store string values and are accessible synchronously via JavaScript on the same origin.

localStorage Persistence

Data in localStorage persists until explicitly cleared by code, the user, or browser data deletion. It survives browser restarts, page refreshes, and tab closes. Capacity is typically 5-10MB per origin depending on browser.

All lessons in this course

  1. localStorage vs sessionStorage
  2. Getting Setting and Removing Items
  3. Listening for Storage Events
  4. Security What Never to Store in Storage
← Back to HTML Academy