HTML maxlength Attribute

Definition and Usage

The maxlength attribute specifies the maximum number of characters allowed in the element.

Applies to

The maxlength attribute can be used on the following elements:

Elements Attribute
<input> maxlength
<textarea> maxlength

Examples

Input Example

An <input> element with a maximum length of 10 characters:

<form action="/action_page.php">
Username: <input type="text" name="usrname" maxlength="10"><br>
<input type="submit" value="Submit">
</form>

Textarea Example

A text area with a maximum length of 50 characters:

<textarea maxlength="50">
Enter text here...
</textarea>

Browser Support

The maxlength attribute has the following browser support for each element:

Element          
input 1.0 2.0 1.0 1.0 1.0
textarea Yes 10.0 4.0 Yes 15.0

Comments