HTML <input> maxlengthAttribute
Example
An <input> element with a maximum length of 10 characters:
<form action="demo_form.php">
Username: <input type="text" name="usrname" maxlength="10"><br>
<input type="submit" value="Submit">
</form>
Username: <input type="text" name="usrname" maxlength="10"><br>
<input type="submit" value="Submit">
</form>
Try it Yourself »
Browser Support
![]()
![]()
![]()
![]()
![]()
All major browsers support the maxlength attribute.
Definition and Usage
The maxlength attribute specifies the maximum number of characters allowed in the <input> element.
Differences between HTML 4.01 and HTML5
None.
Syntax
<input maxlength="number">
Attribute Values
| Value | Description |
|---|---|
| number | The maximum number of characters allowed in the <input> element. |
HTML <input> Tag Other Extensions