Open In App

HTML <textarea> maxlength attribute

Improve
Improve
Like Article
Like
Save
Share
Report

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:

HTML <Textarea> maxlength attribute

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

1. How to specify minimum &maximum number of characters allowed in an input field in HTML ?

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.

2. Create a Character Limit Textarea using HTML CSS and JavaScript

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
Previous
Next
Share your thoughts in the comments
Similar Reads