Rohan Shewale's Blog

LocalStorage used size

May 24, 2025 | 1 Minute Read

A simple script to help you determine how much of localStorage space is currently being used by your application.

let totalSize = 0;

for (let key in localStorage) {
  if (localStorage.hasOwnProperty(key)) {
    let keySize = new Blob([key]).size; // Size of the key
    let valueSize = new Blob([localStorage[key]]).size; // Size of the value
    totalSize += keySize + valueSize;
  }
}

console.log(`Total localStorage size: ${totalSize} bytes`);
console.log(`Total size in KB: ${(totalSize / 1024).toFixed(2)} KiB`);
console.log(`Total size in MB: ${(totalSize / (1024 * 1024)).toFixed(2)} MiB`);

As of writing this article, most browsers allow up to 5MiB of data per origin in localStorage, and 5 MiB of session storage per origin as well — with a typical combined maximum of 10 MB per origin across both.