HTML <textarea> maxlength attribute
The HTML <textarea> maxlength attribute is used to specify the maximum number of characters entered into the textarea element.
Syntax:
<textarea maxlength ="number">
Attribute Value:
Attribute Value
|
Description
|
number
|
It contains a single value number which allows the maximum number of characters in the Textarea element. Its default value is 524288.
|
HTML <textarea> maxlength attribute Examples
Example: This example illustrates the use of textarea max length property in an HTML document.
HTML
<!DOCTYPE html>
< html >
< head >
< title >
textarea maxlength Attribute
</ title >
< style >
body {
text-align: center;
}
</ style >
</ head >
< body >
< textarea
form = "mygeeks"
maxlength = "9"
></ textarea >
< br />
< form id = "mygeeks" >
Name:
< input type = "text" name = "username" />
< input type = "submit" />
</ form >
</ body >
</ html >
|
Output:
Explanation:
- In the above example we Includes a textarea with a maxlength attribute set to 9.
- A form consists of a name input field and a submit button.
- Styled with centered text and fieldset margin.
HTML Textarea maxlength attribute Use Cases
To specify the minimum and maximum number of characters allowed in an input field in HTML, use the “minlength” and “maxlength” attributes, respectively, within the <input> tag.
To create a character limit textarea: Use HTML <textarea> with a maxlength attribute, style with CSS, and validate input length with JavaScript. Update remaining characters dynamically.
Supported Browsers
Last Updated :
11 Mar, 2024
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...