The Current State of HTML5 Forms

The maxlength Attribute

<input type=text maxlength=10>
			<textarea maxlength=20></textarea>

Live Demo




 
Firefox
3.6
Firefox
4+
Safari
5+
Safari Mobile
4+
Chrome
6+
Opera
11+
IE
9
IE
10+
Android
2.3
Input Supported Supported Supported Supported Supported Supported Supported Supported Supported
Textarea No support Supported Supported Supported Supported Supported Not supported Supported Supported

Supported Browser Screenshots

Opera 11.10 Mac

The Low Down

The maxlength attribute limits the number of characters that an input or textarea can accept.

  • Works for texty inputs like text, email, url, etc
  • For textareas: Chrome 10/Safari 5/Firefox 4/Mobile Safari on iOS 4.3.2 will cut off the text as-you-type, or truncate pasted text. Opera 11 and IE 10 PP2 will allow you to keep typing or paste beyond the limit, but validate the length after you submit (better).
  • For inputs: Chrome 10+ will cut off the text as-you-type. Opera 11 will allow you to keep typing, but validate the length after you submit.
  • There are cases where Opera 11 will show the validation message for a textarea briefly but submit the form anyway (need reduced test cast).
  • Doesn't limit placeholder length. ALSO doesn't limit VALUE (a preset value will pass validation.)
  • IE 9 reports support on both inputs and textareas but only works on inputs. IE 10 PP2 brings support for both.