Local Storage vs IndexedDB — What's the Difference?
Local Storage stores simple string key-value pairs synchronously and is limited to a few megabytes; IndexedDB is a full asynchronous, transactional database...
Published November 23, 2026
localStorage stores small string key-value pairs synchronously (about 5 MB); IndexedDB is an asynchronous, transactional database in the browser that stores large structured data, including blobs and files, with indexes and queries.
The concept
localStorage blocks the main thread on each call and only holds strings, so it suits small settings like theme.
IndexedDB handles hundreds of MB, stores objects directly, supports indexes and works in Web Workers, but has a more complex API (libraries like idb or Dexie simplify it).
Choose by data
Practical examples
localStorage
localStorage.setItem('theme', 'dark')
localStorage.getItem('theme')IndexedDB with idb
import { openDB } from 'idb'
const db = await openDB('app', 1, { upgrade(d) { d.createObjectStore('notes', { keyPath: 'id' }) } })
await db.put('notes', { id: 1, text: 'hello' })
await db.get('notes', 1)Storage quota
const { usage, quota } = await navigator.storage.estimate()Common mistakes
- Storing large JSON blobs in localStorage.
- Not handling quota errors.
- Treating either as secure storage.
Key takeaways
- localStorage: small, sync, strings.
- IndexedDB: large, async, structured.
- Neither is for secrets.
FAQ
Which for offline apps?
IndexedDB, often via a service worker cache for assets.
Is data persistent?
Yes, until the user or browser clears it.