HTML maxlength attribute
maxlength
The purpose of the HTML maxlength attribute is to specify the maximum number of characters allowed in a text field of a form.
Supported elements
HTML maxlength attribute supports input element.
Syntax
<input maxlength="value" >.....</input>
Type of value
Number.
Value
A number indicating the maximum number of characters allowed in the text field of a form.
Default value
There is no default value of HTML maxlength attribute.
Supported doctypes
HTML 4.01 strict, HTML 4.01 transitional, HTML 4.01 frameset.
Example of HTML maxlength attribute with input
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Example of HTML maxlength attribute with input</title>
</head>
<body>
<form action="action.php" name="login">
Username : <input type="text" name="user" maxlength="20" /><br/>
Password : <input type="text" name="pass" maxlength="12" /><br/>
</form>
</body>
</html>
Result

View this example in a separate browser window
Example of HTML maxlength attribute with input
Previous: HTML marginwidth attribute
Next: HTML media attribute
Test your Programming skills with w3resource's quiz.
- New Content published on w3resource:
- HTML-CSS Practical: Exercises, Practice, Solution
- Java Regular Expression: Exercises, Practice, Solution
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework
- Angular - JavaScript Framework
- Vue - JavaScript Framework
- Jest - JavaScript Testing Framework