Skip to content

What Is IndexedDB?

IndexedDB is a low-level API built into every modern browser that lets you store large amounts of structured data client-side — including files and blobs. Unlike localStorage and sessionStorage, IndexedDB is:

  • Asynchronous — all operations are non-blocking and event- or Promise-based
  • Transactional — reads and writes happen inside transactions, so your data stays consistent even if something goes wrong mid-operation
  • Object-oriented — you store JavaScript objects directly, not just strings
  • Indexed — you can define indexes on object properties and query by them efficiently
  • Large quota — browsers typically allow hundreds of megabytes to gigabytes (storage is negotiated with the browser, not capped at 5–10 MB)
FeaturelocalStorage / sessionStorageIndexedDB
API styleSynchronousAsynchronous (events / Promises)
Value typesStrings onlyStructured objects, blobs, files
Storage quota~5–10 MBHundreds of MB to GB
QueryingKey lookup onlyKey + indexes on any property
TransactionsNoneFull ACID transactions
Use from workerssessionStorage: no; localStorage: limitedYes — fully usable in Web Workers

The rule of thumb: use Web Storage for small, simple config/preferences. Reach for IndexedDB when you need to store structured records, large data, support offline, or query beyond a single key.

Every IndexedDB database has a name and a version number. Inside a database you create one or more object stores — roughly analogous to tables. Each object store holds records, and each record is a JavaScript object identified by a key.

flowchart LR
  DB["Database
(name + version)"]
  OS1["Object Store
'users'"]
  OS2["Object Store
'posts'"]
  R1["Record
{id:1, name:'Ada'}"]
  R2["Record
{id:2, name:'Alan'}"]
  R3["Record
{id:1, title:'Hello'}"]
  DB --> OS1
  DB --> OS2
  OS1 --> R1
  OS1 --> R2
  OS2 --> R3
IndexedDB structure: database → object stores → records

Use IndexedDB when any of the following apply:

  • You need to store more than a few kilobytes of data per origin
  • Your data is structured (objects with multiple fields) and you want to query or sort it
  • You are building an offline-first or PWA experience and need to cache network responses or sync queues
  • You need to store binary data (images, audio, PDF blobs)
  • You want to share storage access from a Web Worker or Service Worker

Stick with localStorage for simple flags, theme preferences, or small serialised objects where synchronous access is convenient and the data fits comfortably in a few KB.

This module walks through IndexedDB from scratch in five lessons:

OrderLessonWhat you will learn
1What Is IndexedDB? (this lesson)Concepts, structure, and when to use it
2Opening a DatabaseindexedDB.open, versioning, onupgradeneeded
3Object Stores and KeysCreating stores, key paths, auto-increment
4TransactionsRead-only vs read-write, error handling, aborting
5CRUD Operationsadd, put, get, getAll, delete, cursors

Runnable: verifying IndexedDB is available

Section titled “Runnable: verifying IndexedDB is available”

The snippet below opens a database, confirms the name, then deletes it to leave no trace.

Browser Storage
Which of the following is a key difference between IndexedDB and localStorage?
What is an object store in IndexedDB?
Which scenario is the best fit for IndexedDB rather than localStorage?