59

Is there any limit (up to the amount of local storage available) for the key when using localStorage?

i.e. can I do something like:

localStorage.setItem("pretend that this is a 1MB string", "whatever"); 

1 Answer 1

48

Yes, the limit is 5MB per domain. Your string can be as long as you want. The total usage must, however, be under 5 MB.

http://dev.w3.org/html5/webstorage/

http://www.stackoverflow.com/questions/2747285/html5-localstorage-restrictions-and-limits

Sign up to request clarification or add additional context in comments.

5 Comments

The OP was asking about the key length more than the total storage. Those links didn't particularly answer the question. Are you saying key length is infinite, so long as it doesn't exceed the total 5 MB?
@ParchedSquid Just tested on IE9, Chromium 30, Firefox 25; the key can have any length, as long as the total size of the key+value pair falls within the boundaries of the storage (approx 5MB). Code used to test: localStorage.clear();localStorage.setItem(new Array(5e6).join(' '),'');localStorage.key(0).length;
I tested quickly in FF24 with the same result. Thanks for confirming.
Tested in the UIWebView on iOS 8.1 (iPhone 4S) and the limit was ~2.6MB.
is it still only 5mb? 2024

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.