Textarea maxLength attribute

Definition and Usage

maxLength Sets or returns the value of the maxLength attribute of the text area.

The HTML maxLength attribute specifies the maximum number of characters allowed in the text area.

See also:

HTML Reference Manual:HTML <textarea> maxlength Property

Example

Example 1

Get the maximum number of characters allowed in the specific text area:

var x = document.getElementById("myTextarea").maxLength;

Try it yourself

Example 2

Change the maximum number of characters allowed in the text area:

document.getElementById("myTextarea").maxLength = "4";

Try it yourself

Syntax

Return the maxLength property:

textareaObject.maxLength

Set maxLength Property:

textareaObject.maxLength = number

Attribute Value

Value Description
number Specifies the maximum number of characters allowed in the text area.

Technical Details

Return Value: Number, representing the maximum number of characters allowed in the text area.

Browser Support

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
Support 10.0 Support Support Support