Movatterモバイル変換


[0]ホーム

URL:


  1. Web
  2. Web APIs
  3. HTMLTextAreaElement
  4. maxLength

HTMLTextAreaElement: maxLength property

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

ThemaxLength property of theHTMLTextAreaElement interface indicates the maximum number of characters (inUTF-16 code units) allowed to be entered for the value of the<textarea> element, and the maximum number of characters allowed for the value to be valid. It reflects the element'smaxlength attribute.-1 means there is no limit on the length of the value.

Note:Browsers generally prevent users from entering more characters than themaxlength attribute allows. Should the length be longer, the element is considered invalid and theValidityState object'stooLong property will betrue.

Value

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

Example

Given the following HTML:

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

You can use themaxLength property to retrieve or set the<textarea>'smaxlength 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 byMDN contributors.


[8]ページ先頭

©2009-2026 Movatter.jp