← Glossary

What Is IndexedDB?

IndexedDB is a transactional, asynchronous database built into the browser that stores structured JavaScript objects per origin, with far more capacity than cookies or localStorage but no guarantee of permanent retention.

Updated:

IndexedDB is a transactional database built into the browser that lets a web page store large amounts of structured data on the user's device and read it back without a network request. Nothing in it travels to the server automatically, which separates it from cookies. It can store structured JavaScript values and binary objects, works asynchronously, and accommodates larger datasets than Web Storage when the browser's quota allows. Each database belongs to a single origin, so a page on one site cannot open a database created by another.

The API is deliberately low-level. There are no SQL statements and no fixed columns. Code opens a named database, defines object stores inside it, writes records under a primary key, and reads them back through requests that report results as events.

Databases, Object Stores and Indexes

An IndexedDB database is a named container scoped to one origin and tagged with an integer version. Inside it sit one or more object stores, which play the role that tables play in a relational system. Each record in a store is a JavaScript value, and anything the structured clone algorithm can copy is allowed: nested objects, arrays, dates, typed arrays and Blobs. A store can pull its primary key from a property of the stored object through a key path, or generate keys automatically. Automatic keys identify records inside that store; they are not globally unique identifiers.

Indexes make lookups by something other than the primary key practical. If a store holds customer records keyed by account number, an index on the email property lets code fetch a record by email without scanning the whole store. An index can be declared unique, in which case a second write with the same indexed value fails, and it can be compound, built from an array of property names. Objects that lack the indexed property are simply absent from that index.

Schema changes happen only during a version upgrade. Opening the database with a higher version number than the one on disk fires an upgrade event, and that is the only moment when stores or indexes can be created, dropped or redefined. Changing the key path of an existing store means deleting and recreating it, which also deletes its records, so upgrade code usually copies data out first.

Transactions and Asynchronous Access

Every read or write happens inside a transaction that names the object stores it touches and the mode it needs. Read-only transactions can run in parallel, even over the same stores. A readwrite transaction holds its stores so that no other write to them proceeds until it finishes. The versionchange mode is reserved for the upgrade step. If a request inside a transaction fails and the error is left unhandled, the whole transaction aborts and the stores return to their previous state. That rollback lets an application replace several related records atomically when an operation fails. Crash durability is a separate question from whether a transaction completes as a unit.

Transaction lifetime follows the event loop. Requests can be added during the task that creates a transaction and during its request callbacks. Once its work has finished and no further requests are queued, it can commit automatically. Waiting for an unrelated network response may therefore leave no active transaction to receive the next write. A common design fetches the required data first, then opens a short transaction to store it.

Browser transactions use asynchronous requests rather than synchronous disk operations in page code. Results arrive through events, but copying large values and processing results can still consume main-thread time. The same API is available inside Web Workers, where a worker can fetch and store data for offline use without involving the page at all. One durability caveat applies: in some browsers the completion event may fire before data is flushed to disk, so a power failure in that instant can lose the transaction.

Origin Scope, Quotas and Eviction

Storage is partitioned by origin, meaning scheme, host and port together. Two sites on different subdomains of the same domain get separate databases. In several browsers an origin loaded as a third-party iframe receives storage that is further partitioned by the top-level site, which limits reuse of the same stored identifier across unrelated top-level sites. It does not eliminate every possible tracking method.

Capacity is finite and depends on the browser, available storage and persistence policy. An advertised percentage of disk space is a quota ceiling, not a reservation or a promise that every write will succeed. The Storage API can provide an estimate, while applications still need to handle QuotaExceededError. An offline map, for example, should check whether downloading another region is practical and allow old regions to be removed.

Retention is conditional. Best-effort storage can be removed under storage pressure, and browsers may apply additional cleanup policies. Users can clear site data themselves. Private sessions generally use temporary storage that is discarded when the session ends; the underlying implementation varies. An origin can request persistent storage, which can protect it from storage-pressure eviction if granted. That permission does not make the database immune to user deletion, device loss or all browser policies.

IndexedDB vs Web Storage

The IndexedDB vs localStorage question usually comes down to data size, data shape and whether blocking the page is acceptable. The two mechanisms share origin scoping and differ in almost everything else.

PropertyIndexedDBlocalStorage
Value typeStructured-clonable objects, including BlobsStrings only
Access modelAsynchronous, event-based requestsSynchronous calls that block the thread
QueryingPrimary keys, indexes, key ranges, cursorsExact key lookup only
AtomicityMulti-record transactions with rollbackSingle key write at a time
CapacityLarger datasets, subject to browser quotasSmall string datasets with tighter limits
Worker accessAvailable in workersWindow only

localStorage remains the simpler choice for a handful of small settings such as a theme preference or a dismissed-banner flag, because one synchronous call is easier than a transaction. IndexedDB suits anything that needs to be queried, anything large, binary content such as images or audio for offline playback, and any write that must succeed or fail across several records together.

Typical Uses and Limitations

Offline-capable applications are the classic case. A mail client caches message headers and bodies, a mapping tool stores tiles, a note-taking app keeps drafts and synchronises them when connectivity returns. Progressive web apps pair IndexedDB with the Cache API, using the former for structured records and the latter for whole HTTP responses. Logging code sometimes buffers events locally and uploads them in batches.

The limitations follow from the design. Data reaches a server only when code sends it. IndexedDB can hold application state, but it does not automatically attach an authentication credential to a request as a matching cookie does. Because storage can be evicted or cleared, important records need an intentional backup, sync or export strategy. A local-only application should make the consequences of clearing site data clear to its users. And any script running on the origin can read the database, so sensitive data stored there inherits every cross-site scripting risk the page carries.

Frequently asked questions

Is IndexedDB sent to the server automatically?

No. IndexedDB data stays on the device and is never attached to HTTP requests the way cookies are. It reaches a server only if the page's own JavaScript reads it and sends it, for example during a sync step.

Can users delete IndexedDB data?

Yes. Clearing site data in browser settings removes it, and private browsing discards it when the session ends. Browsers may also evict an origin's data under storage pressure unless the origin was granted persistent storage.

When is IndexedDB preferable to localStorage?

When data is large, structured, binary, or needs to be queried by more than one key. It is also the right choice when several records must be written atomically, or when storage must be reachable from a worker.

Does IndexedDB work across subdomains?

No. Databases are scoped to the exact origin, so a different subdomain, scheme or port sees its own empty storage. There is no equivalent of the cookie Domain attribute for widening the scope.

Why do IndexedDB transactions sometimes fail as inactive?

A transaction can commit after its queued work finishes. Awaiting an unrelated operation may let that happen before code adds another request. Prepare data before opening the transaction, or use an appropriate fresh transaction when the later work is ready.