In this section, we will learn what the maxlength attribute is and how to use it.
What is maxlength Attribute in HTML <textarea> Tag?
The maxlength attribute is used in an HTML <textarea> element to declare the maximum number of characters this field can take as its value.
It’s a good practice to use this attribute. Because it will stop malicious users from overloading the textarea with unnecessary data.
HTML maxlength Attribute in <textarea> Tag Syntax:
<textarea maxlength = “maximum number of characters”> </textarea>
<textarea> Tag maxlength Attribute Values
The value we set for the maxlength attribute declares the maximum number of characters the target textarea element can take for its value.
Example: using maxlength attribute in HTML <textarea> tag
See the Pen using maxlength attribute in HTML <textarea> tag by Omid Dehghan (@odehghan) on CodePen.
For this example, the maximum characters that users can put in the textarea field is limited to only 250 characters (Including spaces).