How it works
Cookies live in a store shared by the browser's networking code and document.cookie. When a response carries Set-Cookie, the browser stores the cookie with its domain, path, expiry and flags; for every later request it attaches the matching ones in a Cookie header. document.cookie is a string view of the same store, minus HttpOnly cookies. The cookie spec asks browsers to keep at least 50 cookies per domain and to ignore a cookie whose name plus value exceeds 4,096 bytes; Chrome 156 and Firefox 159 dropped a 4,097-byte one whether it came from script or a header.
Web Storage is a per-origin map of strings (localStorage) plus a per-tab, per-origin map (sessionStorage). Every call is synchronous: the script waits until the browser has read or written the value. Writing a 4 MiB string took about 4–6 ms in Chrome 156 and Firefox 159 (3 runs each). Other same-origin tabs get a storage event when a value changes.
IndexedDB keeps object stores of structured clones, with indexes, inside versioned databases. Every read and write is a request inside a transaction and reports back by event, so the main thread never waits on disk. It's available in windows, dedicated workers and service workers.
The Cache API maps Requests to Responses. Pages can use it, but its main client is a service worker answering fetches offline.
The Storage Standard registers localStorage and sessionStorage with a 5 MiB quota each, and gives IndexedDB, the Cache API and service worker registrations no fixed one: they share the origin's disk quota.
Edge cases
The quota figures held across 3 runs. The last row is a secure-context rule: the Cache API and Cookie Store API exist only over HTTPS or on localhost, while cookies, Web Storage and IndexedDB work over plain HTTP. In a third-party iframe, Chrome 115+, Firefox and Safari partition this storage by the top-level site, so the same embed sees different data on different sites.
Real-world scenario
A note-taking app: the session id is an HttpOnly cookie set by the login response. The theme lives in localStorage and is applied by an inline script in <head>. The note being edited is saved to IndexedDB on every pause in typing, with an outbox store of unsent changes that a service worker or the next page load syncs. The app shell and fonts are in the Cache API. sessionStorage keeps which panel each tab had open, so two tabs don't fight over it.
Trade-offs
Synchronous storage is a feature when you need a value before first paint: reading a theme from localStorage in an inline <script> avoids a flash of the wrong theme, and IndexedDB can't answer that early. It becomes a cost when the data is large or written often, because each write blocks rendering and input.
IndexedDB's API is verbose and event-based. Most apps wrap it in a small promise helper or a library rather than use raw requests; keep the wrapper thin so you still see where transactions start and end.
Cookies cost bandwidth on every request and are readable by the server for free. That's the only reason to choose them.