Tutorials References Menu

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>
Try it Yourself »

Textarea Example

A text area with a maximum length of 50 characters:

<textarea maxlength="50">
Enter text here...
</textarea>
Try it Yourself »

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