16

The default maximum length for a HTML input (<input type="text">) is 524288 characters. That seems like a very peculiar number, why was it chosen?

11
  • 1
    It is documented, at least here. Oct 20, 2014 at 15:21
  • 1
    Is it limited by the spec, or is that just a limitation imposed by certain browsers? bugs.webkit.org/show_bug.cgi?id=44883
    – David
    Oct 20, 2014 at 15:26
  • 2
    w3c doesn't seem to mention it w3.org/TR/html5/… only that it needs to be a positive number and should reflect the intended contents of the input element. Are you this is true across browsers? w3schools is hardly a reliable source.
    – Ben
    Oct 20, 2014 at 15:31
  • 1
    I think that they wanted a value that is not too long to avoid security problems, but enough to store information. Maybe they decided to use a power of 2 and they chosen to be 2^19 just because in hex it looks nice: 80000. Oct 20, 2014 at 15:38
  • 1
    524288 bytes is 512 kilo bytes
    – Ben
    Oct 20, 2014 at 15:48

1 Answer 1

16

According to the w3c the maximum value is unlimited:

maxlength = number [CN]

When the type attribute has the value "text" or "password", this attribute specifies the maximum number of characters the user may enter. This number may exceed the specified size, in which case the user agent should offer a scrolling mechanism. The default value for this attribute is an unlimited number.

Despite that, I have noticed that in Chrome indeed defaults the maxlength to 524288, which seems a 'bug 'to me, or at least a deliberate choice to cap the input to 512KB (thanks to Benjamin Udink ten Cate for pointing that out).

9
  • Ah, so it is 512KB. I assumed it was a totally random number, because it's not actually 512_kilo_bytes, but 512_kibi_bytes. Google converter must use the latest standard
    – Mike
    Oct 20, 2014 at 15:52
  • 4
    @mikemike: That's just marketing. I will keep it to code ;) . It has been this for years, and in my opinion it still is. Jan 27, 2015 at 14:09
  • 1
    I don't understand the rationale, other than to confuse 99.9% of people who know what a [x]byte is (or was). Very annoying! That's what prompted the question initially anyhow, as I just did a quick Google conversion, expecting the number to be 512KB, but instead got a random number
    – Mike
    Jan 27, 2015 at 14:11
  • 4
    "The standard changed recently." This seems like an entirely meaningless statement. The number of bits involved in the representation should be all that matters for coding purposes.
    – codetaku
    Apr 23, 2015 at 18:32
  • 1
    Interesting thing I noticed, looks like Chrome has changed the default max length to -1. It looks like this change occurred recently (within a year or few I'd guess). If you look at some of the web tests in the Chromium GitHub mirror (github.com/chromium/chromium/…) you'll see that it's now testing that the default value is -1. This makes sense since that must be their equivalent of unlimited. Apr 24, 2019 at 0:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.