Course contentsShow
← Web Development
Lesson 772 of 2,98214. Browser StorageFree lesson

Storage Capacity and Limits

Understanding storage quotas (typically 5-10MB per origin) and how browsers enforce limits.

Storage Capacity and Limits

You'll learn: How much data you can store in localStorage/sessionStorage and what happens when you exceed browser limits.

Understanding Storage Quotas

Just like your phone has limited storage for apps and photos, browsers enforce storage limits for each website's localStorage and sessionStorage. These limits prevent websites from consuming unlimited disk space on your device.

Most browsers allocate 5-10MB of storage per origin (origin = protocol + domain + port). This might sound like a lot, but remember: everything is stored as text, so this limit can fill up faster than you think, especially if you're storing large JSON objects or encoded images.

How Browsers Enforce Limits

When you try to store data that would exceed the quota, the browser throws a QuotaExceededError. Your setItem() operation fails, and none of the new data is saved. This is why you should always handle storage operations carefully in production code.

Different browsers have slightly different limits:

  • Chrome/Edge: ~10MB per origin
  • Firefox: ~10MB per origin
  • Safari: ~5MB per origin (may prompt user for larger amounts)

Think of It Like a Backpack

Imagine localStorage as a backpack with a fixed size. You can pack items (data) into it, but once it's full, you can't force more in. You'd need to remove some items first to make room for new ones.

What Affects Your Capacity

Storage is shared across your entire origin. If you store data in multiple keys, they all count toward the same limit. A single huge string in one key has the same impact as many small strings across multiple keys.

Key Takeaway: Browsers limit localStorage/sessionStorage to roughly 5-10MB per origin; exceeding this throws a QuotaExceededError, so always plan for storage constraints and handle errors gracefully.