HTMLTextAreaElement: maxLength property - Web APIs | MDN

Value

A number representing the element's maxlength if present, or -1.

Example

Given the following HTML:

html

<p>
  <label for="comment">Comment</label>
  <textarea id="comment" minlength="10" maxlength="200"></textarea>
</p>

You can use the maxLength property to retrieve or set the <textarea>'s maxlength attribute value:

js

const textareaElement = document.querySelector("#comment");
console.log(`Element's maxLength: ${textareaElement.maxLength}`); // "Element's maxlength: 200"
textareaElement.maxLength = 220; // updates the element's maxlength attribute value

Specifications

Specification
HTML
# dom-textarea-maxlength

Browser compatibility

See also

Help improve MDN

Learn how to contribute

This page was last modified on by MDN contributors.