Attribute: Maxlength

The maxlength attribute specifies the maximum allowed length for the input field. In other words, the maxlength attribute will not let the input control accept more than the allowed number of characters:

HTML file: Displayed by browser:
<form>
First name:
<br /><input type="text" name="firstname" maxlength="10">
<br />
<br />Last name:
<br /><input type="text" name="lastname">
</form>
First name:


Last name:

The attribute does not provide any feedback. If you want to alert the user, you must write JavaScript code. Input restrictions are not foolproof. JavaScript provides many ways to add illegal input. o safely restrict input, restrictions must be checked by the receiver (the server) as well.

Back button Table of Contents Next button