IndexedDB is a low-level browser API for storing large amounts of structured data on the client—including files and blobs. Unlike localStorage, it stores JavaScript objects, supports indexes, and runs work inside transactions.
Use this hub to learn the core ideas, try a live demo, then open the focused CRUD tutorials: Insert, Retrieve, Update, and Delete.
Baseline · Widely available.
Not deprecated. IndexedDB has been stable across browsers since about July 2015. Also available in Web Workers. Same-origin only—one site cannot read another site’s database.
vs Web SQL.
Web SQL is deprecated. Prefer IndexedDB for new offline storage. Think object stores (JS objects) instead of SQL tables.
Vocabulary
Key Concepts
Term
Meaning
Database
Top-level container opened with indexedDB.open(name, version)
Object store
Collection of records (like a table of JS objects)
Key / keyPath
Primary identifier for a record (e.g. id)
Index
Secondary lookup path (e.g. search by email)
Transaction
Atomic unit of work: readonly or readwrite
Cursor
Iterator that walks records with continue()
Upgrade
Schema changes only in onupgradeneeded when the version increases
Syntax
Syntax
syntax.js
indexedDB.open(name, version?)
Then create stores in onupgradeneeded, and run reads/writes inside db.transaction(storeNames, mode).
Task
Pattern
Create store
db.createObjectStore(name, { keyPath }) in upgrade
Insert
store.add(obj) / store.put(obj)
Read
store.get(key) / store.getAll()
Update
store.put(obj) (full replace)
Delete
store.delete(key) / store.clear()
Flow
How It Works
A typical first IndexedDB program follows these steps:
Feature-detect with window.indexedDB.
Open with indexedDB.open('myDb', 1).
Create the store in onupgradeneeded if needed.
On success, keep the IDBDatabase handle.
Start a transaction, get the store, then add / get / put / delete.
One line: open a DB, create stores on upgrade, then CRUD inside transactions.
Frequently Asked Questions
IndexedDB is a browser API for storing large amounts of structured data on the client. You open a database with indexedDB.open(), save JavaScript objects in object stores, and read or change them inside transactions. It works asynchronously so the page stays responsive.
localStorage stores simple key-value strings with a small size limit. IndexedDB stores objects, blobs, and files, supports indexes for fast lookups, and handles much larger datasets. Use localStorage for a few settings; use IndexedDB for offline apps and rich data.
The onupgradeneeded event runs when you open a database with a higher version number than before. Inside it you create or delete object stores and indexes. Normal add/get/delete operations happen later in readwrite or readonly transactions—not during upgrade.
add() inserts a new record and fails if the key already exists. put() inserts or replaces the record with the same key (upsert). Use add() when duplicates must be rejected; use put() for updates and idempotent saves.
IndexedDB groups work into transactions for consistency. A readwrite transaction commits all writes together or rolls back on error. You request a transaction on one or more object store names, then call methods on transaction.objectStore('name').
Open the Insert tutorial next to add records, then Retrieve, Update, and Delete. Each page has live demos and Try It editors focused on one operation.