how many characters are possible in an input field in html?
Asked Answered
S

6

16

What is the "natural" number of allowed characters in an input field in html?

thanks a lot

addition due to the comments

i don't need to send it to the server via post or get. i am going to parse the string via JS.

So if the input is unlimited like @sAc says brings me to two further questions:

  1. What is the longest String JS can handle?
  2. what is the lowest amount of allowed characters for an input in common browsers?(which would be my limit than)
Shutdown answered 24/6, 2010 at 7:39 Comment(3)
Edited to say "characters". Feel free to roll back if I misunderstood.Detent
What do you mean by "like you can read it"? Your question doesn't make sense to me yet.Detent
thanks - characters is better - sorry for my english ;-)Shutdown
A
32

Firefox 3.6.6 on my 32 bit Win 7 machine becomes slow after 1,000,000 characters and totally freezes after 4,000,000.

Chrome crashes somewhere after 8,000,000.

IE8 crashes somewhere after 8,000,000.

Safari crashes somewhere after 2,000,000.

In my testing Chrome/IE8/Safari don't slow down as the size goes up the way Firefox does.

Antitrust answered 2/7, 2010 at 13:34 Comment(1)
@BhimashankarMantur A lot has changed in 10 years. Thanks for adding an update.Antitrust
A
7

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.

Source: http://www.w3.org/TR/html401/interact/forms.html#adef-maxlength

Arlon answered 24/6, 2010 at 7:45 Comment(3)
but nobody knows / has tested how the limitation in common browsers is, isn't it?Shutdown
This limitation probably varies across browsers, JS implementations, server implementation, and possibly even physical hardware limits. This is a textbook example of undefined behavior.Dulcine
@Justin L: Yup that true too.Arlon
A
0

I wouldn't think there is a limit, unless the code has something stopping it (size parameter) or the server can't take any more characters (either a LOT of characters or a bad server).

There is also the 32bit etc. limits depending on the server, I believe.

Acetic answered 24/6, 2010 at 7:46 Comment(1)
I think size-parameter is not quite right? To limit the maximum chars of a field, you have to use the maxlength-attribute. Size is only for visual width of the field.Brebner
B
0

I think that depends on the method you are sending the form with. If you send the form via GET-method it's only 255 chars for the whole query (correct me if I am wrong). The POST-method allows much more...

So in the end you can write millions of chars in a text-field, the question is, if all chars are sent to the server.

In HTML however you've got the possibility to specify how many characters you want to allow. Look at this snippet:

<input type="text" name="email" maxlength="255" />

The maxlength-attribute of the tag, prevents the user from being able to type in more than 255 chars.

Brebner answered 24/6, 2010 at 7:49 Comment(0)
D
0

In a textarea you can enter an unlimited amount of text.

OK, in practice you shouldn't enter megabytes of text or you will run into server limits.

When you the POST method to send the form to the server (which is the usual way), then you can send at least megabytes. When you use the GET method, the whole form is transferred through the querystring and there the limits are in the thousands of characters (the exact value depends on the server and the browser).

Dream answered 24/6, 2010 at 7:52 Comment(0)
W
0

The number of visible characters is dependent on the size of the input element, but also on the style of that element: a wide box put in a shallow container (e.g., a div or form) will not show all the characters in the field.

See W3Schools explanation on INPUT, paying attention to size and maxlength attributes. maxlength specifies the maximum length (in characters) of an input field for "text" or "password" types, size specifies the width of an input field.

Wingspread answered 24/6, 2010 at 7:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.