Your Browser Has a Database. Most Developers Never Use It.
LocalStorage has a 5MB limit and stores only strings. IndexedDB is the real browser database - structured data, no size cap, queryable indexes. I built a local-first notes app to show how it works. Part 3 of the build-it-small series.
Most developers who need to persist data in the browser reach for localStorage. It is simple. It works. But it has real limits:
- 5MB cap (varies by browser)
- Stores only strings - objects need
JSON.stringifyandJSON.parse - Synchronous - it blocks the main thread
- No indexes, no queries
IndexedDB is the alternative. It is built into every major browser, stores structured data without a size cap, operates asynchronously, and supports indexes for querying. Most developers never touch it because the raw API is verbose. But once you wrap it in a few helper functions, it is straightforward.
The API
Opening a database:
const req = indexedDB.open('my-db', 1)
req.onupgradeneeded = (e) => {
const db = e.target.result
const store = db.createObjectStore('notes', { keyPath: 'id', autoIncrement: true })
store.createIndex('updatedAt', 'updatedAt')
}
req.onsuccess = () => {
const db = req.result
// ready to use
}
Reading all records:
const t = db.transaction('notes', 'readonly')
const req = t.objectStore('notes').getAll()
req.onsuccess = () => console.log(req.result)
Writing a record:
const t = db.transaction('notes', 'readwrite')
t.objectStore('notes').add({ title: 'Hello', content: '...', updatedAt: Date.now() })
The pattern is always the same: open a transaction, get the object store, run the operation.
What I Built
For project 03 of the build-it-small series, I built a local-first notes app with a sidebar and editor layout:
- Create, edit, and delete notes
- Search across title and content in real time
- Word count per note
- Timestamps - shows when each note was last updated
- Export all notes as a JSON file
- Auto-save - saves 1.5 seconds after you stop typing, no button needed
- Focus mode - hides the sidebar and header, leaving just the title and text centred on screen. Press Esc to exit- Everything stored in IndexedDB - closes the tab, reopens it, notes are still there
- Zero backend, zero account, zero cost
The notes live entirely on the user's device. No server ever sees them.
Why IndexedDB Over localStorage
For simple key-value pairs and small amounts of data, localStorage is fine. But for anything structured - notes, contacts, tasks, cached API responses - IndexedDB is the right tool:
- No practical size limit (typically 50MB+ depending on available disk)
- Store objects directly, no serialisation needed
- Transactions with rollback on failure
- Index-based querying without loading everything into memory
The Architecture
I split the database logic into a separate db.js module with three functions: getAllNotes, saveNote, and deleteNote. The React app never touches the IndexedDB API directly - it only calls these functions. This keeps the component clean and makes the storage layer easy to swap out or extend.
export async function saveNote(note) {
const db = await openDB()
const now = Date.now()
if (note.id) {
return tx(db, 'readwrite', (s) => s.put({ ...note, updatedAt: now }))
}
return tx(db, 'readwrite', (s) => s.add({ ...note, createdAt: now, updatedAt: now }))
}
The Stack
- React 18 + Vite
- Tailwind CSS
- Native IndexedDB API - no library
- Zero dependencies beyond React
Clone it, run npm install && npm run dev, and start taking notes.
Try It
Source on GitHub: github.com/paolinellih/build-it-small
Look in the 03-indexeddb-notes folder.
Previous: Speech to Text in the Browser